summaryrefslogtreecommitdiff
path: root/pylint/checkers
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2023-03-23 22:53:01 +0100
committerGitHub <noreply@github.com>2023-03-23 21:53:01 +0000
commit07127ee75f3456920ff5117cdbaf8697744b6cfc (patch)
tree4379f57d5bdbfaf94c8c9fd3bea5788e35747210 /pylint/checkers
parent355f4fe5af048cdc5b1be2eb82cd017eadf94553 (diff)
downloadpylint-git-07127ee75f3456920ff5117cdbaf8697744b6cfc.tar.gz
Don't consider ``Union`` to always be a type alias (#8489)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/checkers')
-rw-r--r--pylint/checkers/base/name_checker/checker.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/pylint/checkers/base/name_checker/checker.py b/pylint/checkers/base/name_checker/checker.py
index 1341edc96..616067d1f 100644
--- a/pylint/checkers/base/name_checker/checker.py
+++ b/pylint/checkers/base/name_checker/checker.py
@@ -597,7 +597,13 @@ class NameChecker(_BasicChecker):
inferred = utils.safe_infer(node)
if isinstance(inferred, nodes.ClassDef):
if inferred.qname() == ".Union":
- return True
+ # Union is a special case because it can be used as a type alias
+ # or as a type annotation. We only want to check the former.
+ assert node is not None
+ return not (
+ isinstance(node.parent, nodes.AnnAssign)
+ and node.parent.value is not None
+ )
elif isinstance(inferred, nodes.FunctionDef):
if inferred.qname() == "typing.TypeAlias":
return True