fix(stdlib-stubs): promote os.statvfs and os.sync out of platform conditionals#905
Conversation
…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 |
There was a problem hiding this comment.
Just check for @mpavailable, it may not have () , it may have parameters
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
another possible match is : folder / module / f"{module}.pyi"
solve by checking alist of options , rather than nested if statements
There was a problem hiding this comment.
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>
Typeshed gates
os.statvfsandos.syncinsideif 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 asFalseand hides them, makingfrom os import statvfsreport an unknown import symbol.Changes
build.py— new post-merge steppromote_mp_available_from_conditionals(folder), called aftermerge_docstubs_into_stdlib().os/__init__.pyifor top-levelif sys.platformblocks where everydefis immediately preceded by@mp_available().def(e.g.mkfifo) are left untouched.stdlib/os/__init__.pyi— checked-in output updatedstatvfsandsyncare now unconditionally available at module level; theirif sys.platform != "win32":headers are commented out.Closes: #903