Skip to content

feat(types): enable pyright strict mode#44

Merged
henrylee97 merged 5 commits into
masterfrom
pyright-strict
May 12, 2026
Merged

feat(types): enable pyright strict mode#44
henrylee97 merged 5 commits into
masterfrom
pyright-strict

Conversation

@henrylee97

Copy link
Copy Markdown
Member

Summary

  • Add [tool.pyright] typeCheckingMode = "strict" to pyproject.toml
  • Remove Any import from plare/parser.py; replace Any with object in all __eq__/__ne__ signatures
  • Resolve generic isinstance narrowing issue in State.__eq__ with an is_instance(self, obj) -> TypeGuard[State[T]] instance method — T is bound through self: State[T], so other.items resolves to set[Item[T]]
  • Fix bare typetype[object] in Grammar type alias (test_determinism.py)
  • Fix right: listright: list[type[Token] | str] (test_hash_semantics.py)
  • Add full union type annotation to grammar: dict variable (test_prec_override.py)
  • Remove unused import pytest (test_prec_override.py)

Test plan

  • python -m pyright → 0 errors, 0 warnings
  • python -m pytest tests/ -m "not slow" → 32 passed

henrylee97 and others added 5 commits May 12, 2026 13:34
- 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>
@henrylee97 henrylee97 self-assigned this May 12, 2026
@henrylee97 henrylee97 added the bug Something isn't working label May 12, 2026
@henrylee97
henrylee97 enabled auto-merge (squash) May 12, 2026 13:58
@github-actions

Copy link
Copy Markdown

Pytest Report

Test Results

  • Tests: 33
  • Errors: 0
  • Failures: 0
  • Skipped: 0

Comment by ✨sambyeol/publish-pytest-action

@github-actions

Copy link
Copy Markdown

Pytest Report

Test Results

  • Tests: 33
  • Errors: 0
  • Failures: 0
  • Skipped: 0

Comment by ✨sambyeol/publish-pytest-action

@github-actions

Copy link
Copy Markdown

Super-linter summary

Language Validation result
PYTHON_BLACK Pass ✅
PYTHON_ISORT Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

@henrylee97
henrylee97 merged commit 97ae1f5 into master May 12, 2026
7 checks passed
@henrylee97
henrylee97 deleted the pyright-strict branch May 12, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant