@@ -91,33 +91,27 @@ so it's better not to combine metaclasses and class hierarchies:
9191
9292.. _PEP 673 : https://peps.python.org/pep-0673/#valid-locations-for-self
9393
94- For some builtin types, mypy assumes that their metaclass is :py:class: `abc.ABCMeta `
95- even if it's :py:class: `type `. In those cases, you can either
94+ For some builtin types, mypy may think their metaclass is :py:class: `abc.ABCMeta `
95+ even if it is :py:class: `type ` at runtime . In those cases, you can either:
9696
9797* use :py:class: `abc.ABCMeta ` instead of :py:class: `type ` as the
98- superclass of your metaclass if that works in your use-case,
99- * mute the error with ``# type: ignore[metaclass] ``, or
100- * compute the metaclass' superclass dynamically, which mypy doesn't understand
101- so it will also need to be muted.
98+ superclass of your metaclass if that works in your use-case
99+ * mute the error with ``# type: ignore[metaclass] ``
102100
103101.. code-block :: python
104102
105103 import abc
106104
107- assert type (tuple ) is type # metaclass of tuple is type
105+ assert type (tuple ) is type # metaclass of tuple is type at runtime
108106
109- # the problem:
107+ # The problem:
110108 class M0 (type ): pass
111- class A0 (tuple , metaclass = M1 ): pass # Mypy Error: metaclass conflict
109+ class A0 (tuple , metaclass = M0 ): pass # Mypy Error: metaclass conflict
112110
113- # option 1: use ABCMeta instead of type
111+ # Option 1: use ABCMeta instead of type
114112 class M1 (abc .ABCMeta ): pass
115113 class A1 (tuple , metaclass = M1 ): pass
116114
117- # option 2: mute the error
115+ # Option 2: mute the error
118116 class M2 (type ): pass
119117 class A2 (tuple , metaclass = M2 ): pass # type: ignore [ metaclass ]
120-
121- # option 3: compute the metaclass dynamically
122- class M3 (type (tuple )): pass # type: ignore [ metaclass ]
123- class A3 (tuple , metaclass = M3 ): pass
0 commit comments