python - Why does collections.MutableSet not bestow an update method? -


When implementing a class that works like a set, any collections.MutableSet , Which will provide new classes with many mixing methods, if you implement those methods they want (otherwise, some methods of a set can be applied in the context of other methods. To protect you from this boredom, just go to collections.MutableSet and friends

, ___ __ , add , disconnect

and mixed methods

Inherited set methods and clear , pop , delete , __ ior __ , __ iand __ , __ ixor __ , and __ isub __

(and, Just to make it clear that the update "invariable set methods, set The mixin methods are:

__L____ , __lit___ , __eq __ , ___ __ , __ gt __ , __ gi __ , __ and __ , __ or __ , __sub___ , __ xor __ , and isdisjoint

The set refers to an unchanging set, which is not a naturally update .)

Why between these methods is the update < / Code> not? I am surprised - even unrecognized - even set is in this method, but does not archive .set . For example, this causes the following:

 In  [12]: my_set out [12]:  

Perhaps stranger is that MutableMapping does Code> Update method, while MutableSet does not. AFAICT does not mention any reason for this.

API for MutableSet Gordo van Rossum was designed by his proposal Without the extension, he has specified that:

"This class defines concrete operators, respectively, the union, intersections, symmetric and asymmetric differences, respectively, __or__, __and__, __xor__ And __sub __ "

...

" It also supports the operation of in-placement mutation. =, & Amp; =, ^ ^ =, - = say this Apart from the ABC, whose right operand should have a container, one arbitrarily disqualified, this ABC does not provide the designated methods on the built-in concrete set type which performs almost similar (almost) similar functions. . "

There is no bug or inspection here; Rather, it's a matter of opinion whether you like Guido or do not like.

Zen of Python is something to say about that:

  • One should - and preferably only one way - to do this for.
  • However this may not be clear beforehand unless you are Dutch.

He said, the intangible base classes were made easier to expand. To add your own update () method to your concrete square with update = set .__ ior __ is trivial.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -