Skip to content

refactor: add type hints across the project - #5

Merged
VarunGumma merged 6 commits into
VarunGumma:mainfrom
brkahmed:add-type-hints
Oct 30, 2026
Merged

VarunGumma merged 6 commits into
VarunGumma:mainfrom
brkahmed:add-type-hints

Conversation

@brkahmed

Copy link
Copy Markdown
Contributor

Summary

Add type hints across the project to improve static type checking, IDE support, and code readability.

I used markdown-parser-py in one of my projects and needed stricter type information for better static analysis. While working with the library, I added type hints throughout the codebase.

Changes

  • Added type annotations to MarkdownNode methods and attributes.
  • Added type annotations to MarkdownTree methods and attributes.
  • Added explicit types for internal collections such as list[str] and list[MarkdownNode].
  • Added from __future__ import annotations to support recursive type references.
  • Added missing parameter and return type annotations.
  • Kept the existing behavior unchanged.
  • Existing tests continue to pass.
  • Verified the type hints with strict type checking.

Notes

While adding the type hints, Pylance reported two existing issues in tree.py:

  • title is not None is an unnecessary comparison because title is typed as str.
  • base_delta may be possibly unbound depending on the control flow.

Tooling suggestions

Consider Pyright instead of mypy

I would suggest considering Pyright for static type checking since it integrates directly with Pylance for editor feedback and can handle complex branching.

Consider Ruff for formatting and imports

I would also suggest considering Ruff for formatting, linting, and import sorting. It could replace the current Black + isort setup while providing a significantly faster workflow.

@VarunGumma
VarunGumma merged commit 23537cd into VarunGumma:main Oct 30, 2026
1 check passed
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