From 9a8c171ed81c0c9510386f7a0451682167021d02 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Fri, 20 Jan 2023 16:54:22 +0000 Subject: [PATCH] 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()`. --- mypy/semanal.py | 2 +- test-data/unit/check-classes.test | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index acc485a609e0..176a9e4053a8 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -2181,7 +2181,7 @@ def infer_metaclass_and_bases_from_compat_helpers(self, defn: ClassDef) -> None: if len(defn.base_type_exprs) == 1: base_expr = defn.base_type_exprs[0] if isinstance(base_expr, CallExpr) and isinstance(base_expr.callee, RefExpr): - base_expr.accept(self) + self.analyze_type_expr(base_expr) if ( base_expr.callee.fullname in { diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index fce1aa1768f9..9a38d8f344f7 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -5293,6 +5293,19 @@ class F(six.with_metaclass(t.M)): pass class G: pass [builtins fixtures/tuple.pyi] +[case testSixMetaclassGenericBase] +import six +import abc +from typing import TypeVar, Generic + +T = TypeVar("T") + +class C(six.with_metaclass(abc.ABCMeta, Generic[T])): + pass +class D(six.with_metaclass(abc.ABCMeta, C[T])): + pass +[builtins fixtures/tuple.pyi] + -- Special support for future.utils -- --------------------------------