strengthen pyright detection#38
Open
robin523790 wants to merge 8 commits into
Open
Conversation
…uous fields in construct definitions.
…ed(lambda ctx: 50))`
07bd2e1 to
9653daa
Compare
There was a problem hiding this comment.
Pull request overview
This PR strengthens static type checking (Pyright) around construct_typed dataclass fields by refining typing behavior for csfield()/Default/Const/Computed patterns, aiming to prevent cases that previously passed type checking but failed at runtime.
Changes:
- Added a set of
@overloadsignatures forcsfield()and introducedcsdefault_field()to better model Default-field optionality and forbidden init parameters for Const/Computed/Pass-like constructs. - Updated Construct stubs to improve typing for
Computedand singleton constructs (Tell,Pass,Terminated) used by the new overloads. - Expanded/adjusted tests to cover Default/Computed/Padded behavior and updated expected values accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/test_typed.py |
Updates/adds tests intended to validate Pyright behavior for const/default/computed/padded fields. |
construct-stubs/core.pyi |
Refines stub typing for Computed and makes Tell/Pass/Terminated usable as distinct singleton types. |
construct_typed/dataclass_struct.py |
Adds overload-driven typing for csfield() and adds csdefault_field() to model Default-field semantics. |
construct_typed/__init__.py |
Exports csdefault_field from the package API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+124
to
+137
| orig_subcon = subcon | ||
|
|
||
| # Rename subcon, if doc or parsed are available | ||
| if (doc is not None) or (parsed is not None): | ||
| if doc is not None: | ||
| doc = textwrap.dedent(doc).strip("\n") | ||
| subcon = cs.Renamed(subcon, newdocs=doc, newparsed=parsed) | ||
|
|
||
| if orig_subcon.flagbuildnone is True: | ||
| init = False | ||
| default = None | ||
| else: | ||
| init = True | ||
| default = dataclasses.MISSING |
… Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks" in Tests
…raneous construct parameters.
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.
Above code did not trigger a Pyright error but failed at runtime.
This PR introduces
@overloads tocsfield()that allow Pyright to ensure that:Constfields that are provided now raise errors (as these must only be provided in the declaration)Defaultfields can be provided but do not have to (as the default value may be overriden)This PR includes the migration to uv and the version bump to 0.8.0 found here: #37.
BREAKING CHANGES
This PR introduces breaking changes, thus the version has been bumped to 0.8.0.
Defaultfields are only treated as optional if they have an explicit (and redundant)default=marker. A wrapper methodcsdefault_field()has been provided for convenience.Defaultfield must have thekw_only=marker and must be provided by keyword.