Skip to content

add type stub for os.reload_environ#14938

Merged
AlexWaygood merged 1 commit intopython:mainfrom
guoci:add_sys_reload_environ
Oct 29, 2025
Merged

add type stub for os.reload_environ#14938
AlexWaygood merged 1 commit intopython:mainfrom
guoci:add_sys_reload_environ

Conversation

@guoci
Copy link
Copy Markdown
Contributor

@guoci guoci commented Oct 28, 2025

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

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

@AlexWaygood AlexWaygood changed the title add type stub for sys.reload_environ add type stub for os.reload_environ Oct 29, 2025
Copy link
Copy Markdown
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.

Thank you. It looks like the reason why we forgot to add this is that the CPython team forgot to add this function to __all__ when they added it. This then meant that our tests didn't flag it as missing from the module. (In general, if __all__ is defined in a module, our tests only complain if something is missing from the stub if that thing is included in __all__.)

Would you be interested in also making a PR to CPython to add "reload_environ" to os.__all__? Feel free to tag me on the PR and I can help get it merged

@AlexWaygood AlexWaygood merged commit 1bfd069 into python:main Oct 29, 2025
63 checks passed
@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Oct 29, 2025

@AlexWaygood Should I do this to the other recent typeshed missing stubs as well?

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood Should I do this to the other recent typeshed missing stubs as well?

I think this is the only one where the reason why it wasn't picked up by our tests was that it wasn't included in __all__.

  • sys.__all__ does not exist:
    • the reason why sys.androidapilevel wasn't picked up by our tests despite it being missing is that it only exists on Android, and we don't have any CI jobs in typeshed that run on Android.
    • sys._current_exceptions wasn't flagged as being missing because it starts with a leading underscore, and if a module doesn't have __all__ defined then all symbols that start with leading underscores are assumed to be private by our tests (this one was an exception, since it is documented)
  • sysconfig.__all__ does exist, but I think it's probably intentional that _get_preferred_schemes doesn't exist in __all__ -- the docs for that method say "End users should not use this function". I think since it is documented, probably the best thing is to add it to the stubs... but given that "end users should not use this function", I'm not really sure why it's documented 😆

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Oct 29, 2025

What about enum.show_flag_values (#14928)?

@AlexWaygood
Copy link
Copy Markdown
Member

Good point! Yep, that one should also probably be added to __all__ at runtime!

@AlexWaygood
Copy link
Copy Markdown
Member

@guoci how did you find these, out of interest?

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Oct 30, 2025

@AlexWaygood I wrote a script that matches the CPython reStructuredText documentation against the typeshed type stubs. My goal is to automate the process of integrating typeshed’s type information into the CPython docs.

@AlexWaygood
Copy link
Copy Markdown
Member

Very cool -- you could consider contributing something like that script to stubtest, which is the tool we use in our CI to detect when something is present at runtime but not present in the stub. If something appears in CPython's documentation, that's a pretty good reason to make sure we include it in the stubs. We could probably make sure all objects that are explicitly documented are included in this set here as things that should always be included in the stubs.

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Oct 30, 2025

Sure!

@guoci guoci deleted the add_sys_reload_environ branch November 15, 2025 17:16
@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Feb 22, 2026

@AlexWaygood I have open sourced my tool to find missing stubs at https://github.com/guoci/typeshedding_cpython_docs.

@guoci
Copy link
Copy Markdown
Contributor Author

guoci commented Mar 3, 2026

Here is a list of missing stubs for branch 3.14:

API module src
AbstractEventLoopPolicy asyncio asyncio-policy.rst
AbstractEventLoopPolicy.get_event_loop asyncio asyncio-policy.rst
AbstractEventLoopPolicy.set_event_loop asyncio asyncio-policy.rst
AbstractEventLoopPolicy.new_event_loop asyncio asyncio-policy.rst
DefaultEventLoopPolicy asyncio asyncio-policy.rst
WindowsSelectorEventLoopPolicy asyncio asyncio-policy.rst
WindowsProactorEventLoopPolicy asyncio asyncio-policy.rst
QueueEmptyError concurrent.interpreters concurrent.interpreters.rst
QueueFullError concurrent.interpreters concurrent.interpreters.rst
FTP_TLS.ssl_version ftplib ftplib.rst
MADV_SOFT_OFFLINE mmap mmap.rst
MAP_ALIGNED_SUPER mmap mmap.rst
MAP_CONCEAL mmap mmap.rst
set_error_mode msvcrt msvcrt.rst
OUT_TO_DEFAULT msvcrt msvcrt.rst
OUT_TO_STDERR msvcrt msvcrt.rst
OUT_TO_MSGBOX msvcrt msvcrt.rst
REPORT_ERRMODE msvcrt msvcrt.rst
CrtSetReportMode msvcrt msvcrt.rst
CrtSetReportFile msvcrt msvcrt.rst
CRT_WARN msvcrt msvcrt.rst
CRT_ERROR msvcrt msvcrt.rst
CRT_ASSERT msvcrt msvcrt.rst
CRTDBG_MODE_DEBUG msvcrt msvcrt.rst
CRTDBG_MODE_FILE msvcrt msvcrt.rst
CRTDBG_MODE_WNDW msvcrt msvcrt.rst
CRTDBG_REPORT_MODE msvcrt msvcrt.rst
VC_ASSEMBLY_PUBLICKEYTOKEN msvcrt msvcrt.rst
LIBRARIES_ASSEMBLY_NAME_PREFIX msvcrt msvcrt.rst
RLIMIT_VMEM resource resource.rst
RLIMIT_SBSIZE resource resource.rst
RLIMIT_SWAP resource resource.rst
RLIMIT_NPTS resource resource.rst
RLIMIT_KQUEUES resource resource.rst
RUSAGE_BOTH resource resource.rst
BDADDR_BREDR socket socket.rst
BDADDR_LE_PUBLIC socket socket.rst
BDADDR_LE_RANDOM socket socket.rst
SOL_L2CAP socket socket.rst
SOL_SCO socket socket.rst
SOL_BLUETOOTH socket socket.rst
L2CAP_LM socket socket.rst
SO_HCI_EVT_FILTER socket socket.rst
SO_HCI_PKT_FILTER socket socket.rst
HCI_DEV_NONE socket socket.rst
HCI_CHANNEL_RAW socket socket.rst
HCI_CHANNEL_USER socket socket.rst
HCI_CHANNEL_MONITOR socket socket.rst
HCI_CHANNEL_CONTROL socket socket.rst
HCI_CHANNEL_LOGGING socket socket.rst
SO_REUSEPORT_LB socket socket.rst
_emscripten_info sys sys.rst
_emscripten_info.emscripten_version sys sys.rst
_emscripten_info.runtime sys sys.rst
_emscripten_info.pthreads sys sys.rst
_emscripten_info.shared_memory sys sys.rst
getobjects sys sys.rst
_jit sys sys.rst
_jit.is_available sys sys.rst
_jit.is_enabled sys sys.rst
_jit.is_active sys sys.rst

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.

2 participants