Skip to content

Commit

Permalink
Fix false positive on generic base class with six (#14478)
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
ilevkivskyi authored Jan 20, 2023
1 parent 83660d0 commit 9a8c171
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- --------------------------------

Expand Down

0 comments on commit 9a8c171

Please sign in to comment.