Skip to content

fix(stdlib-stubs): promote os.statvfs and os.sync out of platform conditionals#905

Draft
Josverl with Copilot wants to merge 3 commits into
mainfrom
copilot/update-build-script-os-statvfs
Draft

fix(stdlib-stubs): promote os.statvfs and os.sync out of platform conditionals#905
Josverl with Copilot wants to merge 3 commits into
mainfrom
copilot/update-build-script-os-statvfs

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Typeshed gates os.statvfs and os.sync inside if sys.platform != "win32": blocks. After docstub enrichment those functions gained MicroPython docs/types but stayed inside the conditional — so on Windows, pyright evaluates the guard as False and hides them, making from os import statvfs report an unknown import symbol.

Changes

build.py — new post-merge step

  • Adds promote_mp_available_from_conditionals(folder), called after merge_docstubs_into_stdlib().
  • Scans os/__init__.pyi for top-level if sys.platform blocks where every def is immediately preceded by @mp_available().
  • For matching blocks: comments out the conditional header and de-indents the body to module level.
  • Blocks with any undecorated def (e.g. mkfifo) are left untouched.

stdlib/os/__init__.pyi — checked-in output updated

  • statvfs and sync are now unconditionally available at module level; their if sys.platform != "win32": headers are commented out.
# if sys.platform != "win32":

@mp_available()  # force merge
def statvfs(path) -> Tuple: ...

@mp_available()  # force merge
def sync() -> None: ...

Closes: #903

Copilot AI and others added 2 commits June 17, 2026 09:19
…lib stubs

In typeshed, os.statvfs and os.sync are gated inside `if sys.platform != "win32":`.
After docstub enrichment these functions remained inside that conditional, so on
Windows pyright evaluated the condition as False and hid them — causing
`from os import statvfs` to report an unknown import symbol.

Added `promote_mp_available_from_conditionals()` to build.py that comments out
the `if sys.platform` header and de-indents @mp_available()-decorated functions
to module level. Also updated the checked-in stdlib/os/__init__.pyi to reflect
the result.

Fixes #903

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
…ip in regex

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
break

block_text = "".join(block)
has_mp_available = "@mp_available()" in block_text

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Just check for @mpavailable, it may not have () , it may have parameters

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit — both has_mp_available and the has_undecorated_def check now use startswith("@mp_available") instead of the exact "@mp_available()" string, so bare @mp_available, @mp_available(), and @mp_available(some_arg) all match correctly.

functions are promoted; other platform-conditional blocks are left untouched.
"""
for module in ["os"]:
file_path = folder / module / "__init__.pyi"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

another possible match is : folder / module / f"{module}.pyi"

solve by checking alist of options , rather than nested if statements

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit — replaced the nested if with a candidates list (__init__.pyi, {module}/{module}.pyi, {module}.pyi) and a single next(... if p.exists(), None) lookup.

…lookup

Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Copilot AI requested a review from Josverl June 17, 2026 21:25
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.

statvfs stub missing in uos module

2 participants