Skip to content

3.14 annotation evaluation is deferred #10149

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

Open
nickdrozd opened this issue Dec 22, 2024 · 6 comments · May be fixed by #10381
Open

3.14 annotation evaluation is deferred #10149

nickdrozd opened this issue Dec 22, 2024 · 6 comments · May be fixed by #10381
Assignees
Labels
C: undefined-variable Issues related to 'undefined-variable' check C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code py-version python 3.14 typing
Milestone

Comments

@nickdrozd
Copy link
Contributor

Bug description

In 3.14, evaluation of annotations is deferred. Pylint raises undefined-variable for the field annotation below, but in 3.14 this is a false positive.

class X:
    x: X  # <-- undefined-variable

Configuration

Command used

pylint annotation.py

Pylint output

annotation.py:2:7: E0602: Undefined variable 'X' (undefined-variable)

Expected behavior

no warning

Pylint version

pylint 3.3.2
astroid 3.3.6
Python 3.14.0a3+ (heads/main:2a66dd33dfc, Dec 21 2024, 16:04:14) [GCC 9.4.0]

OS / Environment

No response

Additional dependencies

@nickdrozd nickdrozd added False Positive 🦟 A message is emitted but nothing is wrong with the code py-version labels Dec 22, 2024
@nickdrozd
Copy link
Contributor Author

Also used-before-assignment false positives

@nickdrozd
Copy link
Contributor Author

Python 3.14 is now in beta. The new annotation behavior is handled correctly by Mypy and Ruff.

@Pierre-Sassoulas
Copy link
Member

Do you want to contribute Nick ? Now that the beta is out and available in github actions, there's pylint-dev/astroid#2731 on the astroid side but you can already work on the pylint side even if astroid is not officially 3.14 ready yet :)

We do not work on new features during alphas because we already did in the past and then had to revert some of the things we did before the beta was released. ruff is supported by astral and mypy is supported by dropbox so they can probably afford to make different choices. pylint maintenance is volunteer based (except for CVE, supported by Tidelift), so if no one is intrinsically motivated to do something nothing happen.

@nickdrozd
Copy link
Contributor Author

No, it seems like it will be a lot of work. I am happy to help with PR review though.

Probably it is going to require a complete overhaul of the variables checker. I think it would be a good idea to fix this issue and #9815 and other variable false positives (walrus, etc) all at once.

@jacobtylerwalls jacobtylerwalls added C: used-before-assignment Issues related to 'used-before-assignment' check C: undefined-variable Issues related to 'undefined-variable' check labels May 10, 2025
@jacobtylerwalls
Copy link
Member

I think the patch is just:

diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 32ec31809..e8d12eebb 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -1363,7 +1363,11 @@ class VariablesChecker(BaseChecker):
         checks globals doesn't overrides builtins.
         """
         self._to_consume = [NamesConsumer(node, "module")]
-        self._postponed_evaluation_enabled = is_postponed_evaluation_enabled(node)
+        py_version = self.linter.config.py_version
+        py314_plus = py_version >= (3, 14)
+        self._postponed_evaluation_enabled = (
+            py314_plus or is_postponed_evaluation_enabled(node)
+        )
 
         for name, stmts in node.locals.items():
             if utils.is_builtin(name):

@jacobtylerwalls jacobtylerwalls added the Good first issue Friendly and approachable by new contributors label May 11, 2025
@jacobtylerwalls jacobtylerwalls added this to the 4.0.0 milestone May 11, 2025
@cdce8p
Copy link
Member

cdce8p commented May 11, 2025

@jacobtylerwalls Yeah, mostly. Updating a lot of test cases as well though. I've startet to look into it. Will open a PR for it in the next few days.

@cdce8p cdce8p self-assigned this May 11, 2025
@jacobtylerwalls jacobtylerwalls removed the Good first issue Friendly and approachable by new contributors label May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: undefined-variable Issues related to 'undefined-variable' check C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code py-version python 3.14 typing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants