summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index f1348f6e0..29f774a75 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -1435,3 +1435,27 @@ def is_classdef_type(node: astroid.ClassDef) -> bool:
if isinstance(base, astroid.Name) and base.name == "type":
return True
return False
+
+
+def is_attribute_typed_annotation(
+ node: Union[astroid.ClassDef, astroid.Instance], attr_name: str
+) -> bool:
+ """Test if attribute is typed annotation in current node
+ or any base nodes.
+ """
+ attribute = node.locals.get(attr_name, [None])[0]
+ if (
+ attribute
+ and isinstance(attribute, astroid.AssignName)
+ and isinstance(attribute.parent, astroid.AnnAssign)
+ ):
+ return True
+ for base in node.bases:
+ inferred = safe_infer(base)
+ if (
+ inferred
+ and isinstance(inferred, astroid.ClassDef)
+ and is_attribute_typed_annotation(inferred, attr_name)
+ ):
+ return True
+ return False