Skip to content

Commit 9a8c171

Browse files
authored
Fix false positive on generic base class with six (#14478)
Fixes #14475 The fix is straightforward. We need to use the "guarded accept" at this stage, similar to e.g. `clean_up_bases_and_infer_type_variables()`.
1 parent 83660d0 commit 9a8c171

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ def infer_metaclass_and_bases_from_compat_helpers(self, defn: ClassDef) -> None:
21812181
if len(defn.base_type_exprs) == 1:
21822182
base_expr = defn.base_type_exprs[0]
21832183
if isinstance(base_expr, CallExpr) and isinstance(base_expr.callee, RefExpr):
2184-
base_expr.accept(self)
2184+
self.analyze_type_expr(base_expr)
21852185
if (
21862186
base_expr.callee.fullname
21872187
in {

test-data/unit/check-classes.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5293,6 +5293,19 @@ class F(six.with_metaclass(t.M)): pass
52935293
class G: pass
52945294
[builtins fixtures/tuple.pyi]
52955295

5296+
[case testSixMetaclassGenericBase]
5297+
import six
5298+
import abc
5299+
from typing import TypeVar, Generic
5300+
5301+
T = TypeVar("T")
5302+
5303+
class C(six.with_metaclass(abc.ABCMeta, Generic[T])):
5304+
pass
5305+
class D(six.with_metaclass(abc.ABCMeta, C[T])):
5306+
pass
5307+
[builtins fixtures/tuple.pyi]
5308+
52965309
-- Special support for future.utils
52975310
-- --------------------------------
52985311

0 commit comments

Comments
 (0)