Skip to content

Commit c2052d6

Browse files
author
Sai Asish Y
authored
Fix crash in typecheck checker when metaclass argument is a non-class (#11074)
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
1 parent b0feb02 commit c2052d6

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a crash in the typecheck checker when a class uses a non-class object
2+
(for example a function) as its ``metaclass=`` argument.
3+
4+
Closes #11071

pylint/checkers/typecheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def _determine_callable(
670670

671671
# Try to use the metaclass' __call__ if any.
672672
meta = callable_obj.metaclass()
673-
if meta and isinstance(meta, nodes.NodeNG):
673+
if isinstance(meta, nodes.ClassDef):
674674
meta_call, _, from_builtins = _get_local_callable(meta, "__call__")
675675
if meta_call and not from_builtins:
676676
_check_is_function_def(meta_call)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Regression test for https://github.com/pylint-dev/pylint/issues/11071.
2+
3+
A class whose ``metaclass=`` argument resolves to a plain ``FunctionDef``
4+
(rather than a ``ClassDef``) crashed the typecheck checker when looking up
5+
``__call__`` on the metaclass via ``local_attr``.
6+
"""
7+
8+
# pylint: disable=missing-docstring,too-few-public-methods,invalid-metaclass
9+
10+
11+
def fn():
12+
pass
13+
14+
15+
class C(metaclass=fn):
16+
pass
17+
18+
19+
C()

0 commit comments

Comments
 (0)