Skip to content

(🐞) __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

Merged
merged 2 commits into from
Jul 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions stdlib/__future__.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sys
from typing_extensions import TypeAlias

_VersionInfo: TypeAlias = tuple[int, int, int, str, int]

class _Feature:
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or not...

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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[...]):
    ...

Copy link
Member

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.

def __init__(self, optionalRelease: sys._version_info, mandatoryRelease: sys._version_info, compiler_flag: int) -> None: ...
def getOptionalRelease(self) -> sys._version_info: ...
def getMandatoryRelease(self) -> sys._version_info: ...
def __init__(self, optionalRelease: _VersionInfo, mandatoryRelease: _VersionInfo | None, compiler_flag: int) -> None: ...
def getOptionalRelease(self) -> _VersionInfo: ...
def getMandatoryRelease(self) -> _VersionInfo | None: ...
compiler_flag: int

absolute_import: _Feature
Expand Down