Skip to content

Add type stubs for the rest of _rustlib, _rustlib.iter - #30

Merged
awolverp merged 2 commits into
awolverp:masterfrom
andersk:rustlib-types
Oct 6, 2026
Merged

awolverp merged 2 commits into
awolverp:masterfrom
andersk:rustlib-types

Conversation

@andersk

@andersk andersk commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Add TreeDom, the node classes, AttrsList, Parser, Select, serialize, _is_node_impl, and __all__. Give the __new__ methods of HtmlOptions and XmlOptions parameter types and fix their return types, which mypy rejected. Mark the classes final, since they can't be subclassed, and declare those that can't be constructed with a __new__ that doesn't return.

Register iter in sys.modules as markupever._rustlib.iter, as for a submodule of a package, and set its classes' module to match. Replace _rustlib.pyi with a stub package, _rustlib/__init__.pyi and _rustlib/iter.pyi, since a stub file can't declare a submodule.

andersk and others added 2 commits October 5, 2026 23:45
_rustlib.pyi described only the options, QualName, and AttrsListItems,
so type checkers reported every use of the rest of the module as an
error: mypy found 54 errors in the package, mostly "Module has no
attribute".

Add TreeDom, the node classes, AttrsList, Parser, Select, serialize,
_is_node_impl, and __all__.  Give the __new__ methods of HtmlOptions
and XmlOptions parameter types and fix their return types, which mypy
rejected.  Mark the classes final, since they can't be subclassed, and
declare those that can't be constructed with a __new__ that doesn't
return.

mypy's stubtest now finds no differences from the runtime module,
except that the stub doesn't declare the iter submodule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
The iter submodule was only an attribute of _rustlib, so import
markupever._rustlib.iter failed because _rustlib isn't a package, and
its classes claimed to be in markupever._rustlib.

Register iter in sys.modules as markupever._rustlib.iter, as for a
submodule of a package, and set its classes' module to match.

Replace _rustlib.pyi with a stub package, _rustlib/__init__.pyi and
_rustlib/iter.pyi, since a stub file can't declare a submodule.  At
runtime, Python still imports the extension module rather than the
directory, which has no __init__.py.  Wheels include the stub package,
and mypy and pyright find it there.

mypy's stubtest now finds no differences from the runtime module or
the iter submodule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@awolverp
awolverp merged commit d07581b into awolverp:master Oct 6, 2026
12 checks passed
@andersk
andersk deleted the rustlib-types branch October 6, 2026 10:43
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