Repository navigation
refactor: mark consts as final - #69
Conversation
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Documentation build overview
|
There was a problem hiding this comment.
Pull request overview
Refactors rfc3987_syntax2’s public module-level constants and lazily-loaded globals to be annotated as Final (and related typing refinements) so downstream type checkers treat them as non-rebindable.
Changes:
- Annotated exported constants (
RFC3987_SYNTAX_*) and validator mapping asFinalwith broader container types (Sequence,Mapping). - Converted
T_SYNTAX_VALIDATORto an explicit type-alias style declaration. - Added an Unreleased changelog entry for the refactor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/rfc3987_syntax2/syntax_helpers.py | Adds Final/typing annotations for exported constants and lazy globals; adjusts type alias definition. |
| CHANGELOG.md | Documents the refactor in the Unreleased section. |
Comments suppressed due to low confidence (3)
src/rfc3987_syntax2/syntax_helpers.py:584
# type:ignore[...]is missing the required space (# type: ignore[...]), so this may not be recognized by type checkers.
syntax_parser: Final[Lark] # type:ignore[misc] # lazy loading is Final downstream
src/rfc3987_syntax2/syntax_helpers.py:591
# type:ignore[...]is missing the required space (# type: ignore[...]), so this assignment may still be flagged by type checkers as reassigning aFinal.
grammar = _get_grammar() # type:ignore[misc] # lazy loading is Final downstream
src/rfc3987_syntax2/syntax_helpers.py:595
# type:ignore[...]is missing the required space (# type: ignore[...]), so this assignment may still be flagged by type checkers as reassigning aFinal.
syntax_parser = _get_syntax_parser() # type:ignore[misc] # lazy loading is Final downstream
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
src/rfc3987_syntax2/syntax_helpers.py:127
- Same as
RFC3987_SYNTAX_TERMS: this is a list literal, soFinal[list[T_SYNTAX_PARSER_TERM]]more accurately describes the exported object thanFinal[Sequence[...]](which can imply read-only semantics).
_SYNTAX_PARSER_STARTS: Final[Sequence[T_SYNTAX_PARSER_TERM]] = ["iri", "iri_reference", "absolute_iri"]
src/rfc3987_syntax2/syntax_helpers.py:529
- The comment implies a frozen/read-only mapping, but the value is a plain dict. If you’re only marking it as non-rebindable for typing purposes, consider using
Final[dict[...]]and removing the frozen mapping implication.
RFC3987_SYNTAX_TERM_VALIDATORS: Final[Mapping[str, T_SYNTAX_VALIDATOR]] = { # frozendict / MappingProxyType
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/rfc3987_syntax2/syntax_helpers.py:529
- Inline comment suggests this mapping is a "frozendict / MappingProxyType", but the value is currently a plain dict literal (still mutable at runtime). Either wrap it in a real read-only container, or adjust the comment so it doesn’t imply runtime immutability that isn’t provided.
Finalfor downstream users