Skip to content

Commit 27b07de

Browse files
committed
Add support for future.utils.with_metaclass
Same function signature and basic behavior as six.with_metaclass
1 parent dc6da54 commit 27b07de

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

mypy/newsemanal/semanal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ def update_metaclass(self, defn: ClassDef) -> None:
15051505
* __metaclass__ attribute in Python 2
15061506
* six.with_metaclass(M, B1, B2, ...)
15071507
* @six.add_metaclass(M)
1508+
* future.utils.with_metaclass(M, B1, B2, ...)
15081509
"""
15091510

15101511
# Look for "__metaclass__ = <metaclass>" in Python 2
@@ -1525,7 +1526,8 @@ def update_metaclass(self, defn: ClassDef) -> None:
15251526
base_expr = defn.base_type_exprs[0]
15261527
if isinstance(base_expr, CallExpr) and isinstance(base_expr.callee, RefExpr):
15271528
base_expr.callee.accept(self)
1528-
if (base_expr.callee.fullname == 'six.with_metaclass'
1529+
if (base_expr.callee.fullname in {'six.with_metaclass',
1530+
'future.utils.with_metaclass'}
15291531
and len(base_expr.args) >= 1
15301532
and all(kind == ARG_POS for kind in base_expr.arg_kinds)):
15311533
with_meta_expr = base_expr.args[0]

mypy/semanal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ def update_metaclass(self, defn: ClassDef) -> None:
12691269
* __metaclass__ attribute in Python 2
12701270
* six.with_metaclass(M, B1, B2, ...)
12711271
* @six.add_metaclass(M)
1272+
* future.utils.with_metaclass(M, B1, B2, ...)
12721273
"""
12731274

12741275
# Look for "__metaclass__ = <metaclass>" in Python 2
@@ -1289,7 +1290,8 @@ def update_metaclass(self, defn: ClassDef) -> None:
12891290
base_expr = defn.base_type_exprs[0]
12901291
if isinstance(base_expr, CallExpr) and isinstance(base_expr.callee, RefExpr):
12911292
base_expr.callee.accept(self)
1292-
if (base_expr.callee.fullname == 'six.with_metaclass'
1293+
if (base_expr.callee.fullname in {'six.with_metaclass',
1294+
'future.utils.with_metaclass'}
12931295
and len(base_expr.args) >= 1
12941296
and all(kind == ARG_POS for kind in base_expr.arg_kinds)):
12951297
with_meta_expr = base_expr.args[0]

0 commit comments

Comments
 (0)