Repository navigation
Add type stubs for the rest of _rustlib, _rustlib.iter - #30
Merged
Merged
Conversation
_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
TreeDom, the node classes,AttrsList,Parser,Select,serialize,_is_node_impl, and__all__. Give the__new__methods ofHtmlOptionsandXmlOptionsparameter types and fix their return types, which mypy rejected. Mark the classesfinal, since they can't be subclassed, and declare those that can't be constructed with a__new__that doesn't return.Register
iterinsys.modulesasmarkupever._rustlib.iter, as for a submodule of a package, and set its classes' module to match. Replace_rustlib.pyiwith a stub package,_rustlib/__init__.pyiand_rustlib/iter.pyi, since a stub file can't declare a submodule.