summaryrefslogtreecommitdiff
path: root/pylint/checkers/classes.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r--pylint/checkers/classes.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 82fcc8a61..9f7ea9248 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -79,8 +79,8 @@ from pylint.checkers.utils import (
overrides_a_method,
safe_infer,
unimplemented_abstract_methods,
+ uninferable_final_decorators,
)
-from pylint.constants import PY38_PLUS
from pylint.interfaces import IAstroidChecker
from pylint.utils import get_global_option
@@ -795,6 +795,8 @@ a metaclass class method.",
def open(self) -> None:
self._mixin_class_rgx = get_global_option(self, "mixin-class-rgx")
+ py_version = get_global_option(self, "py-version")
+ self._py38_plus = py_version >= (3, 8)
@astroid.decorators.cachedproperty
def _dummy_rgx(self):
@@ -868,14 +870,16 @@ a metaclass class method.",
def _check_typing_final(self, node: nodes.ClassDef) -> None:
"""Detect that a class does not subclass a class decorated with `typing.final`"""
- if not PY38_PLUS:
+ if not self._py38_plus:
return
for base in node.bases:
ancestor = safe_infer(base)
if not ancestor:
continue
- if isinstance(ancestor, nodes.ClassDef) and decorated_with(
- ancestor, ["typing.final"]
+
+ if isinstance(ancestor, nodes.ClassDef) and (
+ decorated_with(ancestor, ["typing.final"])
+ or (uninferable_final_decorators(ancestor.decorators))
):
self.add_message(
"subclassed-final-class",
@@ -1336,7 +1340,10 @@ a metaclass class method.",
args=(function_node.name, "non-async", "async"),
node=function_node,
)
- if decorated_with(parent_function_node, ["typing.final"]) and PY38_PLUS:
+ if (
+ decorated_with(parent_function_node, ["typing.final"])
+ or uninferable_final_decorators(parent_function_node.decorators)
+ ) and self._py38_plus:
self.add_message(
"overridden-final-method",
args=(function_node.name, parent_function_node.parent.name),