(🐞) __future__._Feature.getMandatoryRelease should be Optional#8232
(🐞) __future__._Feature.getMandatoryRelease should be Optional#8232AlexWaygood merged 2 commits intopython:masterfrom
__future__._Feature.getMandatoryRelease should be Optional#8232Conversation
And it shouldn't use `sys._version_info`
This comment has been minimized.
This comment has been minimized.
|
|
||
| _version_info: TypeAlias = tuple[int, int, int, str, int] | ||
|
|
||
| class _Feature: |
There was a problem hiding this comment.
Might be cool to have this as a
_T_minver = TypeVar("_T_minver", bound=tuple[int, int, int, str, int])
_T_maxver = TypeVar("_T_maxver", bound=tuple[int, int, int, str, int] | None)
class _Feature(Generic[_T_minver, _T_maxver]):
...
So that the runtime constants can be exposed at type checking time
There was a problem hiding this comment.
I don't think that's necessary here tbh, and making classes generic in the stub when they're not at runtime can have some unfortunate consequences.
There was a problem hiding this comment.
mypy doesn't narrow the tuple here.
https://mypy-play.net/?mypy=latest&python=3.10&gist=40fa9e86e067c31b64565ef816390e0a
There was a problem hiding this comment.
Although it does narrow the type here: https://mypy-play.net/?mypy=latest&python=3.10&gist=d7701f4a0f78a3c0e2a2e514ca12d269
There was a problem hiding this comment.
@AlexWaygood it doesn't narrow to the the literal values
There was a problem hiding this comment.
_Featureis private so it's not exposed right?
It is documented, though. And I still think in general we shouldn't make things generic in the stub when they're not at runtime unless there's a compelling use case for it, which I don't really see here.
There was a problem hiding this comment.
There was a problem hiding this comment.
Could you do something like:
class _Feature:
...
class _StubOnlyFeature(_Feature, Generic[...]):
...There was a problem hiding this comment.
Could you do something like:
class _Feature: ... class _StubOnlyFeature(_Feature, Generic[...]): ...
I'm even less a fan of that ;)
I prefer making classes generic in the stub to introducing lies about what class certain objects are at runtime.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
Now have to make sure mypy works with it... |
|
Mypy should be fine, it doesn't look at the values. |
And it shouldn't be a
sys._version_info, it should be a 5-tuple.This is also needed for python/cpython#93628