-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve sys
stubs
#6816
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
Improve sys
stubs
#6816
Conversation
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stdlib/sys.pyi
Outdated
if sys.platform == "win32": | ||
# A tuple of length 5, even though it has more than 5 attributes. | ||
@final | ||
class _WinVersion(_uninstantiable_structseq, tuple[int, int, int, int, str]): | ||
@property | ||
def major(self) -> int: ... | ||
@property | ||
def minor(self) -> int: ... | ||
@property | ||
def build(self) -> int: ... | ||
@property | ||
def platform(self) -> int: ... | ||
@property | ||
def service_pack(self) -> str: ... | ||
@property | ||
def service_pack_minor(self) -> int: ... | ||
@property | ||
def service_pack_major(self) -> int: ... | ||
@property | ||
def suite_mast(self) -> int: ... | ||
@property | ||
def product_type(self) -> int: ... | ||
@property | ||
def platform_version(self) -> tuple[int, int, int]: ... | ||
def getwindowsversion() -> _WinVersion: ... |
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.
Note to self: I will have to spin up a windows virtual machine to check these. Will mark resolved when done.
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.
Typo: suite_mast --> suite_mask
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 have fixed the typo (it predated this PR, FWIW)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
As discussed in python#6816, for some `structseq` classes these attributes are writeable `ClassVar`s, but for other classes, they're read-only `ClassVar`s. Either way, however, it's probably a bad idea to be modifying these attributes, so it makes sense to simply annotate them with `Final` rather than `ClassVar`. Note that [PEP 591](https://www.python.org/dev/peps/pep-0591/) specifically states: > Type checkers should infer a final attribute that is initialized in a class body as being a class variable. Variables should not be annotated with both ClassVar and Final. As such, annotating these attributes as `Final[ClassVar[int]]` would be neither necessary nor possible.
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.
Thanks!
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
There are quite a few errors in the stubs for the
sys
module. Most of these appear to have slipped through the net due to the fact that stubtest isn't much good for this module.For example, take the
sys.flags
object. In typeshed, we type it like this:But at runtime, it actually looks like this:
Yup, that's a variable that has the same name as the class it's an instance of. As a result of this
sys
-module magic, stubtest just hasn't been checking the following documented attributes insys
:sys.flags
sys.version_info
sys.float_info
sys.hash_info
sys.int_info
sys.getwindowsversion()
sys.get_asyncgen_hooks()