-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
(🐞) __future__._Feature.getMandatoryRelease
should be Optional
#8232
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
Conversation
And it shouldn't use `sys._version_info`
This comment has been minimized.
This comment has been minimized.
@@ -1,9 +1,12 @@ | |||
import sys | |||
from typing_extensions import TypeAlias | |||
|
|||
_version_info: TypeAlias = tuple[int, int, int, str, int] | |||
|
|||
class _Feature: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexWaygood it doesn't narrow to the the literal values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Feature
is 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do something like:
class _Feature:
...
class _StubOnlyFeature(_Feature, Generic[...]):
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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