feat(types): enable pyright strict mode#44
Merged
Merged
Conversation
- Add [tool.pyright] typeCheckingMode = "strict" to pyproject.toml - Replace Any with object in all __eq__/__ne__ signatures (StartVariable, Item, State, Rule) - Extract State._items_hash property to expose a non-generic int for equality comparison, avoiding Unknown member access after isinstance narrowing - Fix Grammar type alias to use type[object] | None instead of bare type | None so Parser[T] inference resolves T = object - Annotate grammar dict in test_prec_override with full union type to match Parser.__init__ signature - Fix right: list → list[type[Token] | str] in test_hash_semantics - Remove unused pytest import from test_prec_override Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use TypeGuard[State[object]] in _is_state() so pyright narrows other to State[object] after the guard, making other.items a fully-known set[Item[object]] and allowing the original set comparison to be restored. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eq__ Replace module-level is_state() returning TypeGuard[State[object]] with State.is_instance() classmethod returning TypeGuard[State[T]]. When called as self.is_instance(other), cls is bound to type[State[T]], so T flows from the caller's type parameter into the TypeGuard — narrowing other to State[T] instead of State[object]. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
T is bound through the instance (self: State[T]), not the class alone. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pytest ReportTest Results
Comment by ✨sambyeol/publish-pytest-action |
Pytest ReportTest Results
Comment by ✨sambyeol/publish-pytest-action |
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
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.
Summary
[tool.pyright] typeCheckingMode = "strict"topyproject.tomlAnyimport fromplare/parser.py; replaceAnywithobjectin all__eq__/__ne__signaturesisinstancenarrowing issue inState.__eq__with anis_instance(self, obj) -> TypeGuard[State[T]]instance method —Tis bound throughself: State[T], soother.itemsresolves toset[Item[T]]type→type[object]inGrammartype alias (test_determinism.py)right: list→right: list[type[Token] | str](test_hash_semantics.py)grammar: dictvariable (test_prec_override.py)import pytest(test_prec_override.py)Test plan
python -m pyright→ 0 errors, 0 warningspython -m pytest tests/ -m "not slow"→ 32 passed