Skip to content

Add type hints to sruthi library and integrate mypy type checking#53

Draft
Copilot wants to merge 2 commits intodevelopfrom
copilot/add-type-hints-and-mypy
Draft

Add type hints to sruthi library and integrate mypy type checking#53
Copilot wants to merge 2 commits intodevelopfrom
copilot/add-type-hints-and-mypy

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 26, 2026

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 mypy into the CI build.

Type annotations

  • All public and private methods across client.py, response.py, xmlparse.py, errors.py, and __init__.py are fully annotated
  • Uses from __future__ import annotations for forward reference support across Python 3.7+
  • TYPE_CHECKING guard in response.py avoids a circular import when referencing DataLoader

XMLNone null object extended

Added find(), findall(), and __iter__() to XMLNone so it participates correctly in Union[Element, XMLNone] type narrowing without requiring casts throughout call sites:

class XMLNone:
    def find(self, path: str, namespaces: Any = None) -> None: ...
    def findall(self, path: str, namespaces: Any = None) -> List[Any]: ...
    def __iter__(self) -> Iterator[Any]: ...

Bug fixes surfaced by typing

  • _get_content now raises SruthiError("URL is required") explicitly when url is None, rather than silently proceeding
  • maybe_int handles None input explicitly before attempting int() conversion
  • _parse_index guards against missing set attribute on index name elements
  • _parse_schema skips schemas with no name attribute instead of clobbering an empty-string key

Build integration

  • mypy and types-requests added to test-requirements.txt
  • [mypy] ignore_missing_imports = True added to setup.cfg (third-party libs like defusedxml, xmltodict, flatten-dict lack stubs)
  • typecheck target added to Makefile
  • validate.sh runs make typecheck between linting and tests

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

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
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