From ce5cbce5ba11cdc2f8139ade66feea1e181a7944 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sun, 21 Nov 2021 19:24:08 +0300 Subject: Always treat __class_getitem__ as a classmethod (#1266) * Always treat __class_getitem__ as a classmethod Consider this code: class Foo: def __class_getitem__(cls, *args, **kwargs): return cls Without this change, astroid would treat cls as an instance of Foo, and thus it will think of Foo[bar] also as an instance, while really it is the same as Foo. Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- astroid/nodes/scoped_nodes.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'astroid') diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py index f8c60131..cfc14d72 100644 --- a/astroid/nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes.py @@ -1570,6 +1570,8 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): return "classmethod" if self.name == "__init_subclass__": return "classmethod" + if self.name == "__class_getitem__": + return "classmethod" type_name = "method" -- cgit v1.2.1