Visitar URL original
Add `sys.monitoring` from Python 3.12 by lancelote · Pull Request #10890 · python/typeshed · GitHub
The Wayback Machine - https://web.archive.org/web/20231129134127/https://github.com/python/typeshed/pull/10890
Skip to content
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

Add sys.monitoring from Python 3.12 #10890

Merged
merged 10 commits into from Oct 16, 2023

Conversation

lancelote
Copy link
Contributor

Type annotations for sys.monitoring introduced by python/cpython#103082 (PEP 669) in Python 3.12.

I am not entirely sure my approach is correct as sys.monitoring is a namespace. I refactored sys module into a package, _monitoring.pyi is then imported inside sys/__init__.py. Will appreciate any feedback on it 🙇

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 15, 2023 •

Thanks! I think this is probably the right approach. We already do something similar with os.path: os isn't actually a package at runtime, but is in typeshed.

(Unlike sys.monitoring, of course, import os.path does work at runtime. But I like the "make the fake module private" workaround you're using here to solve that problem :)

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

Ugh. This whole "sys.monitoring is a module, but not one you can import directly, sys isn't actually a package" thing is a pain. It looks like stubtest isn't checking any of the attributes on sys.monitoring in this PR, likely because of the fact that sys.monitoring is actually an instance of types.ModuleType:

>>> import sys
>>> sys.monitoring
<module 'sys.monitoring'>
>>> import types
>>> type(sys.monitoring) is types.ModuleType
True

Stubtest special-cases ModuleType instances in the global namespace specifically here, to avoid checking modules twice, which I think is causing it to just avoid checking anything to do with sys.monitoring: https://github.com/python/mypy/blob/ff9deb3001d9c7cc84a1e2fed9125bf456b1d68b/mypy/stubtest.py#L358-L359

We may have to add some special-casing for sys.monitoring specifically to stubtest. For now, I'll just give this a manual review, though :)

stdlib/sys/_monitoring.pyi Outdated Show resolved Hide resolved
stdlib/sys/_monitoring.pyi Outdated Show resolved Hide resolved
stdlib/sys/_monitoring.pyi Outdated Show resolved Hide resolved
stdlib/sys/_monitoring.pyi Outdated Show resolved Hide resolved
lancelote and others added 5 commits October 16, 2023 14:02
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@github-actions

This comment has been minimized.

lancelote and others added 2 commits October 16, 2023 14:27
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! I'll push a change to fixup a few comments, and then merge :D

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 838dd3a into python:main Oct 16, 2023
67 checks passed
@lancelote
Copy link
Contributor Author

@AlexWaygood Thank you for your time reviewing the PR 🙇

@lancelote lancelote deleted the lancelote/monitoring branch October 16, 2023 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants