Skip to content

🚨 add Pyright static type checking#38

Merged
techouse merged 12 commits intomainfrom
chore/pyright
Jan 31, 2026
Merged

🚨 add Pyright static type checking#38
techouse merged 12 commits intomainfrom
chore/pyright

Conversation

@techouse
Copy link
Owner

@techouse techouse commented Jan 31, 2026

This pull request adds Pyright static type checking to the development workflow, updates type annotations for better compatibility, and improves handling of sequence types in the codebase. It also ensures that type checking works correctly across different Python versions and implementations.

Type checking and development workflow improvements:

  • Added pyright as a development dependency and integrated it into the lint/type check workflow in tox, requirements_dev.txt, and documentation. [1] [2] [3] [4] [5] [6]
  • Added a [tool.pyright] configuration section in pyproject.toml to specify Python version, included source directories, and excluded test and build directories.

Type annotation and compatibility fixes:

  • Updated type annotations for the filter parameter in both EncodeOptions and _encode to use Sequence instead of List for broader compatibility and accuracy. [1] [2]
  • Improved handling of key types in _encode to avoid errors when non-integer keys are used with sequences.
  • Simplified the __new__ method signature in the Undefined singleton for better type compatibility.

Python version and implementation-specific dependency management:

  • Adjusted mypy dependency constraints in both pyproject.toml and requirements_dev.txt to ensure compatibility with different Python versions and PyPy. [1] [2]

Summary by CodeRabbit

  • Chores

    • Added a new static type checker to the development workflow and CI linting.
    • Upgraded and reorganized development tooling and dependency configuration with Python-version-aware constraints.
    • Integrated the new type checker into test and linter runs and config.
  • New Features

    • Filters now accept any sequence types (not limited to lists), broadening accepted inputs.
  • Tests

    • Added unit tests for sequence-based filtering and error-handling fallbacks during decoding.

✏️ Tip: You can customize this high-level summary in your review settings.

@techouse techouse added the test label Jan 31, 2026
@techouse techouse self-assigned this Jan 31, 2026
@techouse techouse requested a review from Copilot January 31, 2026 11:06
@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

Warning

Rate limit exceeded

@techouse has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Adds Pyright to dev tooling and CI, restructures dev dependency/type-checker settings, broadens EncodeOptions.filter and encode logic to accept generic Sequences (excluding str/bytes/bytearray), tweaks Undefined.new typing, and adds tests for sequence-filter and decoder-signature fallback behaviors.

Changes

Cohort / File(s) Summary
Tooling / CI
.github/copilot-instructions.md, pyproject.toml, requirements_dev.txt, tox.ini
Add Pyright config and a dedicated tox testenv; include pyright in linter workflow; restructure dev dependencies (requirements_dev), add linters/plugins, and refine mypy constraints.
Encoding logic & models
src/qs_codec/encode.py, src/qs_codec/models/encode_options.py
Change filter type from List[...] to Sequence[...]; update _encode and filter handling to accept generic Sequence types (exclude str/bytes/bytearray) and treat non-int indices for sequence-like targets as undefined.
Undefined model typing
src/qs_codec/models/undefined.py
Remove precise type annotation from Undefined.__new__ signature (cls: t.Type["Undefined"]cls) — runtime singleton behavior unchanged.
Tests — encode
tests/unit/encode_test.py
Add tests for sequence-filter behavior: ensure non-int keys are ignored for sequences, accept non-list sequences (collections.UserList), and handle mapping.get exceptions during encode.
Tests — decode options
tests/unit/decode_options_test.py
Add tests validating decoder fallback behavior when a decoder exposes an invalid or unavailable __signature__, covering 1-arg, 2-arg, and raising cases.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

dependencies, python

Poem

🐰 I hopped through types and added a light,
Pyright arrived to check through the night,
Sequences now roam where plain lists once stayed,
Tests nibble edges where odd cases played,
A happy hop for tidy code and bright.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description comprehensively covers the changes, objectives, and rationale, but does not follow the provided template structure with required sections like 'Type of change', 'How Has This Been Tested', and 'Checklist'. Restructure the description to follow the repository template: add explicit 'Type of change' section with checkboxes, 'How Has This Been Tested' section with test descriptions, and complete the checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding Pyright static type checking to the project's development workflow.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/pyright

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates Pyright as a secondary static type checker to complement mypy, strengthens type annotations for better cross-checker compatibility, and refines version-specific dependency constraints for mypy. The changes ensure more robust type checking across different Python versions and implementations (CPython, PyPy).

Changes:

  • Added Pyright to the development tooling and CI linting workflow
  • Updated type annotations from List to Sequence for filter parameters to improve type accuracy
  • Refined mypy dependency constraints with version-specific conditions for Python <3.9 and PyPy
  • Added conditional logic in _encode to handle non-integer keys when accessing sequence objects

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tox.ini Adds pyright testenv and integrates it into the linters workflow
pyproject.toml Adds pyright to dev dependencies with version-specific mypy constraints and Pyright configuration
requirements_dev.txt Updates mypy dependency constraints with Python version conditions and adds pyright
.github/copilot-instructions.md Updates linters documentation to include pyright in the toolchain list
src/qs_codec/models/encode_options.py Changes filter type annotation from List to Sequence
src/qs_codec/encode.py Changes filter parameter type and adds conditional handling for non-integer keys in sequences
src/qs_codec/models/undefined.py Simplifies __new__ method signature by removing explicit type hints

@codacy-production
Copy link

codacy-production bot commented Jan 31, 2026

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a718ae2) 1261 1261 100.00%
Head commit (5300242) 1267 (+6) 1267 (+6) 100.00% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#38) 19 19 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a718ae2) to head (5300242).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #38   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1261      1267    +6     
=========================================
+ Hits          1261      1267    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/qs_codec/models/encode_options.py (1)

70-75: ⚠️ Potential issue | 🟡 Minor

Update the filter docstring to mention sequences.

The field now accepts sequences, but the docstring still says “list.” Please update for accuracy.

Suggested change
-    - If a list is provided, only those keys/indices are retained.
+    - If a sequence is provided, only those keys/indices are retained.

As per coding guidelines: Keep docstrings descriptive and parity-focused; match the existing module docstring style.

src/qs_codec/encode.py (1)

73-80: ⚠️ Potential issue | 🟠 Major

Filter now accepts Sequence, but runtime still only honors list/tuple.

With the updated type, passing a non-list/tuple sequence (e.g., range) will be silently ignored. Please broaden the runtime checks to match the new contract, while excluding strings/bytes.

Suggested fix
@@
-import typing as t
+import typing as t
+from collections.abc import Sequence
@@
-        elif isinstance(options.filter, (list, tuple)):
-            obj_keys = list(options.filter)
+        elif isinstance(options.filter, Sequence) and not isinstance(options.filter, (str, bytes, bytearray)):
+            obj_keys = list(options.filter)
@@
-    elif isinstance(filter, (list, tuple)):
+    elif isinstance(filter, Sequence) and not isinstance(filter, (str, bytes, bytearray)):
         # Iterable filter restricts traversal to a fixed key/index set.
         obj_keys = list(filter)

Also applies to: 170-170, 318-321

@techouse techouse changed the title Chore/pyright 🚨 add pyright Jan 31, 2026
@techouse techouse changed the title 🚨 add pyright 🚨 add Pyright static type checking Jan 31, 2026
@techouse techouse requested a review from Copilot January 31, 2026 11:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

@techouse techouse requested a review from Copilot January 31, 2026 11:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

@techouse techouse requested a review from Copilot January 31, 2026 11:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

@techouse techouse merged commit 7091425 into main Jan 31, 2026
23 checks passed
@techouse techouse deleted the chore/pyright branch January 31, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants