-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(🎁) Add a StubOnlyBase
decorator for types that don't actually extend things, but do in the stubs (like Generic
)
#956
Comments
StubOnlyGeneric
annotation for generic types that don't extend Generic
StubOnlyGeneric
decorator for generic types that don't extend Generic
StubOnlyGeneric
decorator for generic types that don't extend Generic
StubOnlyBase
decorator for types that don't actually extend things, but do in the stubs (like Generic
)
I like this idea! It would reduce the need for PRs like python/cpython#29355, which corrects an annoying inconsistency between the stub file and the runtime code, but is unlikely to get merged (no real use case, if we're honest). |
Isn't the use case making the stubs more accurate mainly around type parameters? |
That's the use case for making |
As per the OP, my use case is mainly around |
I think we might be talking at cross purposes 🙂 As I said in my first message in this thread, I agree with your case — I like your idea! I was saying that there wasn't much of a use case for my previous PR to cpython that I linked to here, and that I liked your idea because it would reduce the need for PRs to cpython such as the one I linked to. My "no real use case, if we're honest" comment was referring to my PR to cpython, not your idea here 🙂 |
I think python/typeshed#7436 would be a really nice use case for this. The existing There already is I guess getting this into Python would require a PEP? CC: @srittau, @JelleZijlstra |
StubOnlyBase
decorator for types that don't actually extend things, but do in the stubs (like Generic
)StubOnlyBase
decorator for types that don't actually extend things, but do in the stubs (like Generic
)
There are existing classes that extend things in an abstract way, like ABCs, and things that are
Generic
in theory but not in reality, for example all thecollections
(the collection classes are notGeneric
s, they define__class_getitem__
) and some are still not subscribe-able but state they are in the stubs, for instance_collections_abc.dict_keys
or any of the collections pre 3.9.It could be used something like:
Mapping
doesn't actually extendGeneric
, butContainer
defines__class_getitem__
, so that would also need to be updated in the stubs.This might help resolve python/mypy#3186, but still indicate that it's not actually one of the bases.
I think a change like this would make the stubs much more understandable and closer to the actual implementation, also fixing issues about older python versions not working properly with the current stubs(python/mypy#11529).
I personally find it very confusing when referencing the stubs that the bases are often false.
No idea how this would be used in a real life annotation, but a workaround that works is:
python/typeshed#6312 (comment)
python/typeshed#6257
Obligatory shill to #953, which I think would render this moot.
The text was updated successfully, but these errors were encountered: