-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve reference resolution for deferred-annotations-within-classes #4509
Conversation
9aff492
to
ed317be
Compare
ed317be
to
cfec627
Compare
PR Check ResultsEcosystemℹ️ ecosystem check detected changes. (+2, -2, 0 error(s)) airflow (+2, -2)
+ airflow/models/dagbag.py:104:40: F401 [*] `airflow.models.dag.DAG` imported but unused
- airflow/models/dagbag.py:104:40: TCH001 Move application import `airflow.models.dag.DAG` into a type-checking block
+ airflow/models/taskmixin.py:177:45: F401 [*] `airflow.models.operator.Operator` imported but unused
- airflow/models/taskmixin.py:177:45: TCH001 Move application import `airflow.models.operator.Operator` into a type-checking block
BenchmarkLinux
Windows
|
728c881
to
51c431e
Compare
cfec627
to
00fa963
Compare
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) ([changelog](https://togithub.com/charliermarsh/ruff/releases)) | `^0.0.269` -> `^0.0.270` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/compatibility-slim/0.0.269)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/confidence-slim/0.0.269)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.270`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.270) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.269...v0.0.270) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-bandit`] Implement `paramiko-call` (`S601`) by [@​scop](https://togithub.com/scop) in [https://github.com/charliermarsh/ruff/pull/4500](https://togithub.com/charliermarsh/ruff/pull/4500) - \[`flake8-pyi`] Add autofix for PYI009 by [@​qdegraaf](https://togithub.com/qdegraaf) in [https://github.com/charliermarsh/ruff/pull/4583](https://togithub.com/charliermarsh/ruff/pull/4583) - \[`flake8-pyi`] Implement `PYI013` by [@​density](https://togithub.com/density) in [https://github.com/charliermarsh/ruff/pull/4517](https://togithub.com/charliermarsh/ruff/pull/4517) - \[`pylint`] Add `duplicate-value` (`W0130`) by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4515](https://togithub.com/charliermarsh/ruff/pull/4515) - \[`pylint`] Add `named_expr_without_context` (`W0131`) by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4531](https://togithub.com/charliermarsh/ruff/pull/4531) - \[`ruff`] Extend `RUF005` to recursive and literal-literal concatenations by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4557](https://togithub.com/charliermarsh/ruff/pull/4557) - \[`ruff`] Make ambiguous-unicode detection sensitive to 'word' context by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4552](https://togithub.com/charliermarsh/ruff/pull/4552) - \[`ruff`] Name ambiguous characters by [@​covracer](https://togithub.com/covracer) in [https://github.com/charliermarsh/ruff/pull/4448](https://togithub.com/charliermarsh/ruff/pull/4448) ##### Settings - Implement `--extend-fixable` option by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4297](https://togithub.com/charliermarsh/ruff/pull/4297) - Support new `extend-per-file-ignores` setting by [@​aacunningham](https://togithub.com/aacunningham) in [https://github.com/charliermarsh/ruff/pull/4265](https://togithub.com/charliermarsh/ruff/pull/4265) ##### Bug Fixes - Fix RUF010 auto-fix with parenthesis by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4524](https://togithub.com/charliermarsh/ruff/pull/4524) - Parenthesize more sub-expressions in f-string conversion by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4535](https://togithub.com/charliermarsh/ruff/pull/4535) - Fix false-positive for TRY302 if exception cause is given by [@​153957](https://togithub.com/153957) in [https://github.com/charliermarsh/ruff/pull/4559](https://togithub.com/charliermarsh/ruff/pull/4559) - Fix `# isort: split` comment detection in nested blocks by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4584](https://togithub.com/charliermarsh/ruff/pull/4584) - Avoid some false positives in dunder variable assigments by [@​scop](https://togithub.com/scop) in [https://github.com/charliermarsh/ruff/pull/4508](https://togithub.com/charliermarsh/ruff/pull/4508) - Fix UP032 auto-fix with integers by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4525](https://togithub.com/charliermarsh/ruff/pull/4525) - Improve reference resolution for deferred-annotations-within-classes by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4509](https://togithub.com/charliermarsh/ruff/pull/4509) - Improve handling of `__qualname__`, `__module__`, and `__class__` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4512](https://togithub.com/charliermarsh/ruff/pull/4512) - Include empty success test in JUnit output by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4537](https://togithub.com/charliermarsh/ruff/pull/4537) - Fix SIM110 and SIM111 ranges by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4545](https://togithub.com/charliermarsh/ruff/pull/4545) - Ignore `#region` code folding marks in eradicate rules by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4546](https://togithub.com/charliermarsh/ruff/pull/4546) - Avoid infinite loop for required imports with isort: off by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4581](https://togithub.com/charliermarsh/ruff/pull/4581) - Make B007 fix relevance stricter by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4607](https://togithub.com/charliermarsh/ruff/pull/4607) - Introduce `tab-size` to correcly calculate the line length with tabulations by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4167](https://togithub.com/charliermarsh/ruff/pull/4167) - Visit `TypeVar` and `NewType` name arguments by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4627](https://togithub.com/charliermarsh/ruff/pull/4627) - Improve `Message` sorting performance by [@​MichaReiser](https://togithub.com/MichaReiser) in [https://github.com/charliermarsh/ruff/pull/4624](https://togithub.com/charliermarsh/ruff/pull/4624) #### New Contributors - [@​hoel-bagard](https://togithub.com/hoel-bagard) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4516](https://togithub.com/charliermarsh/ruff/pull/4516) - [@​density](https://togithub.com/density) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4517](https://togithub.com/charliermarsh/ruff/pull/4517) - [@​Mr-Pepe](https://togithub.com/Mr-Pepe) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4540](https://togithub.com/charliermarsh/ruff/pull/4540) - [@​153957](https://togithub.com/153957) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4559](https://togithub.com/charliermarsh/ruff/pull/4559) - [@​covracer](https://togithub.com/covracer) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4448](https://togithub.com/charliermarsh/ruff/pull/4448) **Full Changelog**: astral-sh/ruff@v0.0.269...v0.0.270 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS45OC40IiwidXBkYXRlZEluVmVyIjoiMzUuOTguNCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Signed-off-by: Renovate Bot <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Hello @charliermarsh , I do not know if this issue caused the new false-positive error in such code: from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .. import some_module
def some_function(param: str) -> some_module.SupportedAdapters:
from .. import some_module # To fight with circular import, like this is util function <-- this import is reported unused F401
return cast(
some_module.SupportedAdapters,
import_string(f"some_path_here.adapters{param}")(value="init_value"),
) Or maybe the adapter pattern should use something else? If everything is valid on |
Hmm, running |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) ([changelog](https://togithub.com/charliermarsh/ruff/releases)) | `==0.0.269` -> `==0.0.270` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/compatibility-slim/0.0.269)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/confidence-slim/0.0.269)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.270`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.270) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.269...v0.0.270) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-bandit`] Implement `paramiko-call` (`S601`) by [@​scop](https://togithub.com/scop) in [https://github.com/charliermarsh/ruff/pull/4500](https://togithub.com/charliermarsh/ruff/pull/4500) - \[`flake8-pyi`] Add autofix for PYI009 by [@​qdegraaf](https://togithub.com/qdegraaf) in [https://github.com/charliermarsh/ruff/pull/4583](https://togithub.com/charliermarsh/ruff/pull/4583) - \[`flake8-pyi`] Implement `PYI013` by [@​density](https://togithub.com/density) in [https://github.com/charliermarsh/ruff/pull/4517](https://togithub.com/charliermarsh/ruff/pull/4517) - \[`pylint`] Add `duplicate-value` (`W0130`) by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4515](https://togithub.com/charliermarsh/ruff/pull/4515) - \[`pylint`] Add `named_expr_without_context` (`W0131`) by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4531](https://togithub.com/charliermarsh/ruff/pull/4531) - \[`ruff`] Extend `RUF005` to recursive and literal-literal concatenations by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4557](https://togithub.com/charliermarsh/ruff/pull/4557) - \[`ruff`] Make ambiguous-unicode detection sensitive to 'word' context by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4552](https://togithub.com/charliermarsh/ruff/pull/4552) - \[`ruff`] Name ambiguous characters by [@​covracer](https://togithub.com/covracer) in [https://github.com/charliermarsh/ruff/pull/4448](https://togithub.com/charliermarsh/ruff/pull/4448) ##### Settings - Implement `--extend-fixable` option by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4297](https://togithub.com/charliermarsh/ruff/pull/4297) - Support new `extend-per-file-ignores` setting by [@​aacunningham](https://togithub.com/aacunningham) in [https://github.com/charliermarsh/ruff/pull/4265](https://togithub.com/charliermarsh/ruff/pull/4265) ##### Bug Fixes - Fix RUF010 auto-fix with parenthesis by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4524](https://togithub.com/charliermarsh/ruff/pull/4524) - Parenthesize more sub-expressions in f-string conversion by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4535](https://togithub.com/charliermarsh/ruff/pull/4535) - Fix false-positive for TRY302 if exception cause is given by [@​153957](https://togithub.com/153957) in [https://github.com/charliermarsh/ruff/pull/4559](https://togithub.com/charliermarsh/ruff/pull/4559) - Fix `# isort: split` comment detection in nested blocks by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4584](https://togithub.com/charliermarsh/ruff/pull/4584) - Avoid some false positives in dunder variable assigments by [@​scop](https://togithub.com/scop) in [https://github.com/charliermarsh/ruff/pull/4508](https://togithub.com/charliermarsh/ruff/pull/4508) - Fix UP032 auto-fix with integers by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4525](https://togithub.com/charliermarsh/ruff/pull/4525) - Improve reference resolution for deferred-annotations-within-classes by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4509](https://togithub.com/charliermarsh/ruff/pull/4509) - Improve handling of `__qualname__`, `__module__`, and `__class__` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4512](https://togithub.com/charliermarsh/ruff/pull/4512) - Include empty success test in JUnit output by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4537](https://togithub.com/charliermarsh/ruff/pull/4537) - Fix SIM110 and SIM111 ranges by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4545](https://togithub.com/charliermarsh/ruff/pull/4545) - Ignore `#region` code folding marks in eradicate rules by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4546](https://togithub.com/charliermarsh/ruff/pull/4546) - Avoid infinite loop for required imports with isort: off by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4581](https://togithub.com/charliermarsh/ruff/pull/4581) - Make B007 fix relevance stricter by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4607](https://togithub.com/charliermarsh/ruff/pull/4607) - Introduce `tab-size` to correcly calculate the line length with tabulations by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4167](https://togithub.com/charliermarsh/ruff/pull/4167) - Visit `TypeVar` and `NewType` name arguments by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4627](https://togithub.com/charliermarsh/ruff/pull/4627) - Improve `Message` sorting performance by [@​MichaReiser](https://togithub.com/MichaReiser) in [https://github.com/charliermarsh/ruff/pull/4624](https://togithub.com/charliermarsh/ruff/pull/4624) #### New Contributors - [@​hoel-bagard](https://togithub.com/hoel-bagard) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4516](https://togithub.com/charliermarsh/ruff/pull/4516) - [@​density](https://togithub.com/density) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4517](https://togithub.com/charliermarsh/ruff/pull/4517) - [@​Mr-Pepe](https://togithub.com/Mr-Pepe) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4540](https://togithub.com/charliermarsh/ruff/pull/4540) - [@​153957](https://togithub.com/153957) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4559](https://togithub.com/charliermarsh/ruff/pull/4559) - [@​covracer](https://togithub.com/covracer) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4448](https://togithub.com/charliermarsh/ruff/pull/4448) **Full Changelog**: astral-sh/ruff@v0.0.269...v0.0.270 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/pyrainbird). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDIuNCIsInVwZGF0ZWRJblZlciI6IjM1LjEwMi40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Thanks @charliermarsh , this is the small example for reproduction (please note that this NOTE: all these files are located inside the same package adapter.py from __future__ import annotations
from utils import get_name
class Adapter:
def __repr__(self) -> str:
return f"{get_name()}()" main.py from utils import get_adapter
if __name__ == "__main__":
adapter = get_adapter()
print(repr(adapter)) utils.py from __future__ import annotations
from typing import cast, TYPE_CHECKING
from django.utils.module_loading import import_string
if TYPE_CHECKING:
from adapter import Adapter
def get_adapter() -> Adapter:
from adapter import Adapter # this import is marked unused, but deleting it will cause NameError
return cast(Adapter, import_string("adapter.Adapter")())
def get_name() -> str:
return "MyAdapter" Run it out with/without problematic string: ╰─ python main.py
MyAdapter()
╰─ python main.py
Traceback (most recent call last):
File "/home/user/ruff_example/main.py", line 4, in <module>
adapter = get_adapter()
^^^^^^^^^^^^^
File "/home/user/ruff_example/utils.py", line 14, in get_adapter
return cast(Adapter, import_string("adapter.Adapter")())
^^^^^^^
NameError: name 'Adapter' is not defined |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) ([changelog](https://togithub.com/charliermarsh/ruff/releases)) | `==0.0.269` -> `==0.0.270` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/compatibility-slim/0.0.269)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.270/confidence-slim/0.0.269)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.270`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.270) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.269...v0.0.270) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-bandit`] Implement `paramiko-call` (`S601`) by [@​scop](https://togithub.com/scop) in [https://github.com/charliermarsh/ruff/pull/4500](https://togithub.com/charliermarsh/ruff/pull/4500) - \[`flake8-pyi`] Add autofix for PYI009 by [@​qdegraaf](https://togithub.com/qdegraaf) in [https://github.com/charliermarsh/ruff/pull/4583](https://togithub.com/charliermarsh/ruff/pull/4583) - \[`flake8-pyi`] Implement `PYI013` by [@​density](https://togithub.com/density) in [https://github.com/charliermarsh/ruff/pull/4517](https://togithub.com/charliermarsh/ruff/pull/4517) - \[`pylint`] Add `duplicate-value` (`W0130`) by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4515](https://togithub.com/charliermarsh/ruff/pull/4515) - \[`pylint`] Add `named_expr_without_context` (`W0131`) by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4531](https://togithub.com/charliermarsh/ruff/pull/4531) - \[`ruff`] Extend `RUF005` to recursive and literal-literal concatenations by [@​hoel-bagard](https://togithub.com/hoel-bagard) in [https://github.com/charliermarsh/ruff/pull/4557](https://togithub.com/charliermarsh/ruff/pull/4557) - \[`ruff`] Make ambiguous-unicode detection sensitive to 'word' context by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4552](https://togithub.com/charliermarsh/ruff/pull/4552) - \[`ruff`] Name ambiguous characters by [@​covracer](https://togithub.com/covracer) in [https://github.com/charliermarsh/ruff/pull/4448](https://togithub.com/charliermarsh/ruff/pull/4448) ##### Settings - Implement `--extend-fixable` option by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4297](https://togithub.com/charliermarsh/ruff/pull/4297) - Support new `extend-per-file-ignores` setting by [@​aacunningham](https://togithub.com/aacunningham) in [https://github.com/charliermarsh/ruff/pull/4265](https://togithub.com/charliermarsh/ruff/pull/4265) ##### Bug Fixes - Fix RUF010 auto-fix with parenthesis by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4524](https://togithub.com/charliermarsh/ruff/pull/4524) - Parenthesize more sub-expressions in f-string conversion by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4535](https://togithub.com/charliermarsh/ruff/pull/4535) - Fix false-positive for TRY302 if exception cause is given by [@​153957](https://togithub.com/153957) in [https://github.com/charliermarsh/ruff/pull/4559](https://togithub.com/charliermarsh/ruff/pull/4559) - Fix `# isort: split` comment detection in nested blocks by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4584](https://togithub.com/charliermarsh/ruff/pull/4584) - Avoid some false positives in dunder variable assigments by [@​scop](https://togithub.com/scop) in [https://github.com/charliermarsh/ruff/pull/4508](https://togithub.com/charliermarsh/ruff/pull/4508) - Fix UP032 auto-fix with integers by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4525](https://togithub.com/charliermarsh/ruff/pull/4525) - Improve reference resolution for deferred-annotations-within-classes by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4509](https://togithub.com/charliermarsh/ruff/pull/4509) - Improve handling of `__qualname__`, `__module__`, and `__class__` by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4512](https://togithub.com/charliermarsh/ruff/pull/4512) - Include empty success test in JUnit output by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4537](https://togithub.com/charliermarsh/ruff/pull/4537) - Fix SIM110 and SIM111 ranges by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4545](https://togithub.com/charliermarsh/ruff/pull/4545) - Ignore `#region` code folding marks in eradicate rules by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4546](https://togithub.com/charliermarsh/ruff/pull/4546) - Avoid infinite loop for required imports with isort: off by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4581](https://togithub.com/charliermarsh/ruff/pull/4581) - Make B007 fix relevance stricter by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4607](https://togithub.com/charliermarsh/ruff/pull/4607) - Introduce `tab-size` to correcly calculate the line length with tabulations by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4167](https://togithub.com/charliermarsh/ruff/pull/4167) - Visit `TypeVar` and `NewType` name arguments by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4627](https://togithub.com/charliermarsh/ruff/pull/4627) - Improve `Message` sorting performance by [@​MichaReiser](https://togithub.com/MichaReiser) in [https://github.com/charliermarsh/ruff/pull/4624](https://togithub.com/charliermarsh/ruff/pull/4624) #### New Contributors - [@​hoel-bagard](https://togithub.com/hoel-bagard) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4516](https://togithub.com/charliermarsh/ruff/pull/4516) - [@​density](https://togithub.com/density) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4517](https://togithub.com/charliermarsh/ruff/pull/4517) - [@​Mr-Pepe](https://togithub.com/Mr-Pepe) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4540](https://togithub.com/charliermarsh/ruff/pull/4540) - [@​153957](https://togithub.com/153957) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4559](https://togithub.com/charliermarsh/ruff/pull/4559) - [@​covracer](https://togithub.com/covracer) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4448](https://togithub.com/charliermarsh/ruff/pull/4448) **Full Changelog**: astral-sh/ruff@v0.0.269...v0.0.270 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDIuMTAiLCJ1cGRhdGVkSW5WZXIiOiIzNS4xMDIuMTAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Summary
This PR modifies our symbol-resolution logic to better align with Pyright and other type checkers when handling deferred annotations in nested scopes.
By way of example, one of our oldest open issues points to Ruff raising a false-positive unused import here:
The problem is that
Optional[datetime.datetime]
is evaluated last, sincefrom __future__ import annotations
is present. When we go to evaluate it, we see thatdatetime
is already assigned in the scope, and resolve to that.I did some research, and it looks like Pyright (and Mypy too) defer to the module scope when resolving such annotations, and fallback to resolving locally. For example, this works fine too:
This PR modifies our resolution logic to match Pyright's behavior, which in turn closes two long-standing issues. Note that this is a deviation from Pyflakes, but I think it's good to be more in-line with the type checkers.
Relevant Pyright issue: microsoft/pyright#2644.
Relevant Pyright commit: microsoft/pyright@27bf8c1f2.
Closes #1401.
Closes #2248.