| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
I like this PR, it looks like it could fix many issues. But I have some questions:
|
Sorry, something went wrong.
|
@ilevkivskyi The short answer to 1 and 3 is that, when it comes to certain details, the PR represents a WIP due to the exact requirements not being known.
In the context of the full PR, the equality becomes very questionable. And even if we do want it to hold, the duplication won't be necessary. (The conversion of extras into bases will no longer skip builtins here.) EDIT: Looking at this again, I recalled the reason for not eliminating the duplicates yet. It's Generator and the fact that on Python 3.4 and earlier its extra companion is GeneratorType, which cannot be inherited from. For the time being, I settled on a blanket ban on automatically inserting builtins as bases; hence the duplication in cases where we do want to derive from a builtin. |
Sorry, something went wrong.
|
Superseded by #283. Many of the ideas here went into that PR, and it closes most of the same issues. Thanks! |
Sorry, something went wrong.
Here I am adding tests as discussed with @bintoro (related to #207). These tests actually revealed three small bugs: - Old style classes in Python don't have `__mro__`. - We should use `__extra__` instead of extra in Python2 (since no kwargs in classes). - We should allow overriding `__subclasshook__` by subclasses.
| Back | FazBrowse Home | New Git URL |
I don't expect this to be reviewed anytime soon, but the effort is now fairly complete, so might as well put it out there for comments.
Resolves #136
Resolves #202
Resolves #203
At the heart of #136 is a conflation between type compatibility and subtype relationships. Even though Sequence[Manager] is compatible with Sequence[Employee], it's not a subclass of it. Rather, both derive from Sequence[+T_co].
To address this, the PR introduces a new helper is_compatible(), which implements the "is consistent with or a subtype of" relation. In short, it does what issubclass() has been doing until now.
The practical end result is that
issubclass() is no longer applicable to the special types Any, Union, etc.
is_compatible() always works — if neither argument is a special type, is_compatible(T1, T2) reduces to issubclass(T1, T2)
issubclass() acquires its normal semantics w.r.t. generics:
whereas:
Commit summary
There are three commits:
Notes
Full parity is preserved in using unparameterized types in place of the corresponding collections.abc classes in isinstance() and issubclass() calls:
The intent has been not to mess with the types' behavior. That said, the introduction of is_compatible() yields a couple of automatic improvements regarding Any:
The merging of Specific asserts #205 caused a huge conflict in the tests. I will look into it eventually if there's interest in merging this.
The proposal is compatible with the plan to convert some of the collection types to protocols, if that's still on the table.