Skip to content

Conversation

sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Jul 21, 2025

Summary

Emit errors for the following assignments:

class C:
    CLASS_LEVEL_CONSTANT: Final[int] = 1

C.CLASS_LEVEL_CONSTANT = 2
C().CLASS_LEVEL_CONSTANT = 2

Test Plan

Updated and new MD tests

@sharkdp sharkdp added ty Multi-file analysis & type inference ecosystem-analyzer labels Jul 21, 2025
Copy link
Contributor

github-actions bot commented Jul 21, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@sharkdp sharkdp force-pushed the david/final-attributes branch from 70f58cd to 61741ef Compare July 21, 2025 11:03
@sharkdp sharkdp marked this pull request as ready for review July 21, 2025 11:03
Comment on lines +200 to +203
# TODO: this should be an error
c.INSTANCE_FINAL_A = 2
# TODO: this should be an error
c.INSTANCE_FINAL_B = 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implementing this for implicit instance attributes is much more involved, so I'm putting this PR up as a first increment.

Copy link
Contributor

ecosystem-analyzer results

No changes detected ✅
Full report with detailed diff

@sharkdp sharkdp merged commit b6579ea into main Jul 21, 2025
37 checks passed
@sharkdp sharkdp deleted the david/final-attributes branch July 21, 2025 12:27
dcreager added a commit that referenced this pull request Jul 21, 2025
* main: (25 commits)
  [ty] Sync vendored typeshed stubs (#19461)
  [ty] Extend tuple `__len__` and `__bool__` special casing to also cover tuple subclasses (#19289)
  [ty] bump docstring-adder pin (#19458)
  [ty] Disallow assignment to `Final` class attributes (#19457)
  Update dependency ruff to v0.12.4 (#19442)
  Update pre-commit hook astral-sh/ruff-pre-commit to v0.12.4 (#19443)
  Update rui314/setup-mold digest to 702b190 (#19441)
  Update taiki-e/install-action action to v2.56.19 (#19448)
  Update Rust crate strum_macros to v0.27.2 (#19447)
  Update Rust crate strum to v0.27.2 (#19446)
  Update Rust crate rand to v0.9.2 (#19444)
  Update Rust crate serde_json to v1.0.141 (#19445)
  Fix `unreachable` panic in parser (#19183)
  [`ruff`] Support byte strings (`RUF055`) (#18926)
  [ty] Avoid second lookup for `infer_maybe_standalone_expression` (#19439)
  [ty] Implemented "go to definition" support for import statements (#19428)
  [ty] Avoid secondary tree traversal to get call expression for keyword arguments (#19429)
  [ty] Add goto definition to playground (#19425)
  [ty] Add support for `@warnings.deprecated` (#19376)
  [ty] make `del x` force local resolution of `x` in the current scope (#19389)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem-analyzer ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants