GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — Add __orig_bases__ to Generic by hmc-cs-mdrissi · Pull Request #7827 · python/typeshed Conversation
This comment has been minimized.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Hmm, experimenting with pyright I don't see a difference locally with this change. If I try swapping to class and doing class Generic: __orig_bases__: ClassVar[tuple[type, ...]] It does look like pyright uses it. But downside is it causes other aspects of generic to no longer work. Alternative that's safer for type checkers is add |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm fine with this if we can figure out a way to add it to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I'm unsure how to make Generic stub declare this. It looks like each type checker special cases generic in ways that makes me unclear if it's possible to make them happy. Alternative approach I experimented with was, class Generic: def __class_getitem__(cls, params: Any) -> Any: ... __orig_bases__: tuple[type, ...] This approach breaks pyright's type variable binding logic. It does make I also tested adding it to _SpecialForm. That looks to be a noop and does nothing. The current approach of _GenericSpecialForm also looks to be a noop. Amusingly deleting Generic entirely does affect type checkers and causes mypy to crash (pyright runs, with many thousands of errors). My guess is to add it to Generic will require each type checker to add some logic for this special case as they likely all have non standard handling for Generic as a type stub. Unsure it's worthwhile doing a feature request to each type checker to handle I do agree this use case is pretty niche though and my guess is if type lie isn't worth it is probably better to close pr. edit: Well I'll mention it to pyright and maybe take a look at mypy eventually if it can be small contribution there. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
In general, trying to type various aspects of the runtime implementation of typing has been notoriously fragile with little benefit.
So yeah, nice if you could make it work for cheap, but seems like that's not the case :-) Maybe we should put a comment warning in the file. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Supporttype.__orig_bases__ as defined in PEP 560
There was an error while loading. Please reload this page.