Add type hints to sruthi library and integrate mypy type checking#53
Draft
Add type hints to sruthi library and integrate mypy type checking#53
Conversation
Co-authored-by: metaodi <538415+metaodi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add type hints and integrate mypy for type checking
Add type hints to sruthi library and integrate mypy type checking
Feb 26, 2026
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.
The library lacked type annotations, making it harder to catch type errors statically and reducing IDE support. This PR adds type hints throughout the codebase and wires
mypyinto the CI build.Type annotations
client.py,response.py,xmlparse.py,errors.py, and__init__.pyare fully annotatedfrom __future__ import annotationsfor forward reference support across Python 3.7+TYPE_CHECKINGguard inresponse.pyavoids a circular import when referencingDataLoaderXMLNonenull object extendedAdded
find(),findall(), and__iter__()toXMLNoneso it participates correctly inUnion[Element, XMLNone]type narrowing without requiring casts throughout call sites:Bug fixes surfaced by typing
_get_contentnow raisesSruthiError("URL is required")explicitly whenurl is None, rather than silently proceedingmaybe_inthandlesNoneinput explicitly before attemptingint()conversion_parse_indexguards against missingsetattribute on index name elements_parse_schemaskips schemas with nonameattribute instead of clobbering an empty-string keyBuild integration
mypyandtypes-requestsadded totest-requirements.txt[mypy] ignore_missing_imports = Trueadded tosetup.cfg(third-party libs likedefusedxml,xmltodict,flatten-dictlack stubs)typechecktarget added toMakefilevalidate.shrunsmake typecheckbetween linting and tests💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.