Skip to content

Conversation

sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Jul 8, 2025

Summary

Implement this suggestion by @AlexWaygood.

image

@sharkdp sharkdp added internal An internal refactor or improvement ty Multi-file analysis & type inference diagnostics Related to reporting of diagnostics. labels Jul 8, 2025
Comment on lines +1692 to +1698
let range =
previous_definition.full_range(self.db(), self.module());
diagnostic.annotate(
self.context
.secondary(range)
.message("Symbol declared as `Final` here"),
);
Copy link
Contributor Author

@sharkdp sharkdp Jul 8, 2025

Choose a reason for hiding this comment

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

This is a fallback that currently can't be triggered, I believe, because there are no other annotated definitions that would allow a Final annotation. I guess it doesn't hurt to leave this in here, but I can also remove it.

In particular, function parameters are not allowed to be annotated with Final:

Final may only be used in assignments or variable annotations. Using it in any other position is an error. In particular, Final can’t be used in annotations for function arguments

https://typing.python.org/en/latest/spec/qualifiers.html#uppercase-final

This is something that we still have to implement (added a note to the ticket for typing.Final).

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

😍

Copy link
Contributor

github-actions bot commented Jul 8, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@sharkdp sharkdp merged commit 1a09988 into main Jul 8, 2025
40 checks passed
@sharkdp sharkdp deleted the david/touchup-final-diagnostic branch July 8, 2025 18:29
UnboundVariable pushed a commit to UnboundVariable/ruff that referenced this pull request Jul 10, 2025
…re_help

* 'main' of https://github.com/astral-sh/ruff: (34 commits)
  [docs] add capital one to who's using ruff (astral-sh#19248)
  [`pyupgrade`] Keyword arguments in `super` should suppress the `UP008` fix (astral-sh#19131)
  [`flake8-use-pathlib`] Add autofixes for `PTH100`, `PTH106`, `PTH107`, `PTH108`, `PTH110`, `PTH111`, `PTH112`, `PTH113`, `PTH114`, `PTH115`, `PTH117`, `PTH119`, `PTH120` (astral-sh#19213)
  [ty] Do not run `mypy_primer.yaml` when all changed files are Markdown files (astral-sh#19244)
  [`flake8-bandit`] Make example error out-of-the-box (`S412`) (astral-sh#19241)
  [`pydoclint`] Make example error out-of-the-box (`DOC501`) (astral-sh#19218)
  [ty] Add "kind" to completion suggestions
  [ty] Add type information to `all_members` API
  [ty] Expand API of `all_members` to return a struct
  [ty] Ecosystem analyzer PR comment workflow (astral-sh#19237)
  [ty] Merge `ty_macros` into `ruff_macros` (astral-sh#19229)
  [ty] Fix `ClassLiteral.into_callable` for dataclasses (astral-sh#19192)
  [ty] `dataclasses.field` support (astral-sh#19140)
  [ty] Fix panic for attribute expressions with empty value (astral-sh#19069)
  [ty] Return `CallableType` from `BoundMethodType.into_callable_type` (astral-sh#19193)
  [`flake8-bugbear`] Support non-context-manager calls in `B017` (astral-sh#19063)
  [ty] Improved diagnostic for reassignments of `Final` symbols (astral-sh#19214)
  [ty] Use full range for assignment definitions (astral-sh#19211)
  [`pylint`] Update `missing-maxsplit-arg` docs and error to suggest proper usage (`PLC0207`) (astral-sh#18949)
  [ty] Add `set -eu` to mypy-primer script (astral-sh#19212)
  ...

# Conflicts:
#	crates/ty_python_semantic/src/types/class.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Related to reporting of diagnostics. internal An internal refactor or improvement ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants