Skip to content

Commit 001e4a7

Browse files
authored
Use double quotes in Metaclass related errors (#10341)
1 parent dd72094 commit 001e4a7

13 files changed

+39
-39
lines changed

docs/source/metaclasses.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ so it's better not to combine metaclasses and class hierarchies:
9393
class A1(metaclass=M1): pass
9494
class A2(metaclass=M2): pass
9595
96-
class B1(A1, metaclass=M2): pass # Mypy Error: Inconsistent metaclass structure for 'B1'
96+
class B1(A1, metaclass=M2): pass # Mypy Error: Inconsistent metaclass structure for "B1"
9797
# At runtime the above definition raises an exception
9898
# TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
9999

mypy/semanal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ def analyze_metaclass(self, defn: ClassDef) -> None:
16741674
elif isinstance(defn.metaclass, MemberExpr):
16751675
metaclass_name = get_member_expr_fullname(defn.metaclass)
16761676
if metaclass_name is None:
1677-
self.fail("Dynamic metaclass not supported for '%s'" % defn.name, defn.metaclass)
1677+
self.fail('Dynamic metaclass not supported for "%s"' % defn.name, defn.metaclass)
16781678
return
16791679
sym = self.lookup_qualified(metaclass_name, defn.metaclass)
16801680
if sym is None:
@@ -1691,10 +1691,10 @@ def analyze_metaclass(self, defn: ClassDef) -> None:
16911691
self.defer(defn)
16921692
return
16931693
if not isinstance(sym.node, TypeInfo) or sym.node.tuple_type is not None:
1694-
self.fail("Invalid metaclass '%s'" % metaclass_name, defn.metaclass)
1694+
self.fail('Invalid metaclass "%s"' % metaclass_name, defn.metaclass)
16951695
return
16961696
if not sym.node.is_metaclass():
1697-
self.fail("Metaclasses not inheriting from 'type' are not supported",
1697+
self.fail('Metaclasses not inheriting from "type" are not supported',
16981698
defn.metaclass)
16991699
return
17001700
inst = fill_typevars(sym.node)
@@ -1713,7 +1713,7 @@ def analyze_metaclass(self, defn: ClassDef) -> None:
17131713
# Inconsistency may happen due to multiple baseclasses even in classes that
17141714
# do not declare explicit metaclass, but it's harder to catch at this stage
17151715
if defn.metaclass is not None:
1716-
self.fail("Inconsistent metaclass structure for '%s'" % defn.name, defn)
1716+
self.fail('Inconsistent metaclass structure for "%s"' % defn.name, defn)
17171717
else:
17181718
if defn.info.metaclass_type.type.has_base('enum.EnumMeta'):
17191719
defn.info.is_enum = True

mypyc/irbuild/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def transform_name_expr(builder: IRBuilder, expr: NameExpr) -> Value:
8888
if (isinstance(expr.node, Var) and is_none_rprimitive(builder.node_type(expr))
8989
and expr.node.is_inferred):
9090
builder.error(
91-
"Local variable '{}' has inferred type None; add an annotation".format(
91+
'Local variable "{}" has inferred type None; add an annotation'.format(
9292
expr.node.name),
9393
expr.node.line)
9494

mypyc/test-data/commandline.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ d1 = {1: 2}
180180

181181
# Make sure we can produce an error when we hit the awful None case
182182
def f(l: List[object]) -> None:
183-
x = None # E: Local variable 'x' has inferred type None; add an annotation
183+
x = None # E: Local variable "x" has inferred type None; add an annotation
184184
for i in l:
185185
if x is None:
186186
x = i

mypyc/test-data/exceptions.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,14 @@ L5:
413413
L6:
414414
if is_error(a) goto L17 else goto L9
415415
L7:
416-
r7 = raise UnboundLocalError("local variable 'a' referenced before assignment")
416+
r7 = raise UnboundLocalError('local variable "a" referenced before assignment')
417417
if not r7 goto L14 (error at lol:9) else goto L8 :: bool
418418
L8:
419419
unreachable
420420
L9:
421421
if is_error(b) goto L18 else goto L12
422422
L10:
423-
r8 = raise UnboundLocalError("local variable 'b' referenced before assignment")
423+
r8 = raise UnboundLocalError('local variable "b" referenced before assignment')
424424
if not r8 goto L14 (error at lol:9) else goto L11 :: bool
425425
L11:
426426
unreachable
@@ -489,7 +489,7 @@ L3:
489489
L4:
490490
if is_error(v) goto L13 else goto L7
491491
L5:
492-
r8 = raise UnboundLocalError("local variable 'v' referenced before assignment")
492+
r8 = raise UnboundLocalError('local variable "v" referenced before assignment')
493493
if not r8 goto L9 (error at f:7) else goto L6 :: bool
494494
L6:
495495
unreachable

mypyc/test-data/refcount.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,12 +840,12 @@ L2:
840840
L3:
841841
if is_error(y) goto L10 else goto L5
842842
L4:
843-
r2 = raise UnboundLocalError("local variable 'y' referenced before assignment")
843+
r2 = raise UnboundLocalError('local variable "y" referenced before assignment')
844844
unreachable
845845
L5:
846846
if is_error(z) goto L11 else goto L7
847847
L6:
848-
r3 = raise UnboundLocalError("local variable 'z' referenced before assignment")
848+
r3 = raise UnboundLocalError('local variable "z" referenced before assignment')
849849
unreachable
850850
L7:
851851
r4 = CPyTagged_Add(y, z)

mypyc/test-data/run-primitives.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ delAttribute()
369369
delAttributeMultiple()
370370
with assertRaises(AttributeError):
371371
native.global_var
372-
with assertRaises(NameError, "local variable 'dummy' referenced before assignment"):
372+
with assertRaises(NameError, 'local variable "dummy" referenced before assignment'):
373373
delLocal(True)
374374
assert delLocal(False) == 10
375-
with assertRaises(NameError, "local variable 'dummy' referenced before assignment"):
375+
with assertRaises(NameError, 'local variable "dummy" referenced before assignment'):
376376
delLocalLoop()
377377
[out]
378378
(1, 2, 3)

mypyc/transform/uninit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def split_blocks_at_uninits(blocks: List[BasicBlock],
7272
line=op.line))
7373
raise_std = RaiseStandardError(
7474
RaiseStandardError.UNBOUND_LOCAL_ERROR,
75-
"local variable '{}' referenced before assignment".format(src.name),
75+
'local variable "{}" referenced before assignment'.format(src.name),
7676
op.line)
7777
error_block.ops.append(raise_std)
7878
error_block.ops.append(Unreachable())

test-data/unit/check-classes.test

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,11 +3823,11 @@ class B(object, A): # E: Cannot determine consistent method resolution order (MR
38233823
__iter__ = readlines
38243824

38253825
[case testDynamicMetaclass]
3826-
class C(metaclass=int()): # E: Dynamic metaclass not supported for 'C'
3826+
class C(metaclass=int()): # E: Dynamic metaclass not supported for "C"
38273827
pass
38283828

38293829
[case testDynamicMetaclassCrash]
3830-
class C(metaclass=int().x): # E: Dynamic metaclass not supported for 'C'
3830+
class C(metaclass=int().x): # E: Dynamic metaclass not supported for "C"
38313831
pass
38323832

38333833
[case testVariableSubclass]
@@ -4170,13 +4170,13 @@ class C(B):
41704170
class X(type): pass
41714171
class Y(type): pass
41724172
class A(metaclass=X): pass
4173-
class B(A, metaclass=Y): pass # E: Inconsistent metaclass structure for 'B'
4173+
class B(A, metaclass=Y): pass # E: Inconsistent metaclass structure for "B"
41744174

41754175
[case testMetaclassNoTypeReveal]
41764176
class M:
41774177
x = 0 # type: int
41784178

4179-
class A(metaclass=M): pass # E: Metaclasses not inheriting from 'type' are not supported
4179+
class A(metaclass=M): pass # E: Metaclasses not inheriting from "type" are not supported
41804180

41814181
A.x # E: "Type[A]" has no attribute "x"
41824182

@@ -4235,7 +4235,7 @@ reveal_type(list(Explicit)) # N: Revealed type is "builtins.list[builtins.int*]
42354235
from typing import Tuple
42364236

42374237
class M(Tuple[int]): pass
4238-
class C(metaclass=M): pass # E: Invalid metaclass 'M'
4238+
class C(metaclass=M): pass # E: Invalid metaclass "M"
42394239

42404240
[builtins fixtures/tuple.pyi]
42414241

@@ -4309,9 +4309,9 @@ A.x # E: "Type[A]" has no attribute "x"
43094309
from typing import Any
43104310
M = 0 # type: int
43114311
MM = 0
4312-
class A(metaclass=M): # E: Invalid metaclass 'M'
4312+
class A(metaclass=M): # E: Invalid metaclass "M"
43134313
y = 0
4314-
class B(metaclass=MM): # E: Invalid metaclass 'MM'
4314+
class B(metaclass=MM): # E: Invalid metaclass "MM"
43154315
y = 0
43164316
reveal_type(A.y) # N: Revealed type is "builtins.int"
43174317
A.x # E: "Type[A]" has no attribute "x"
@@ -4973,16 +4973,16 @@ class A(object): pass
49734973
def f() -> type: return M
49744974
class C1(six.with_metaclass(M), object): pass # E: Unsupported dynamic base class "six.with_metaclass"
49754975
class C2(C1, six.with_metaclass(M)): pass # E: Unsupported dynamic base class "six.with_metaclass"
4976-
class C3(six.with_metaclass(A)): pass # E: Metaclasses not inheriting from 'type' are not supported
4977-
@six.add_metaclass(A) # E: Metaclasses not inheriting from 'type' are not supported \
4976+
class C3(six.with_metaclass(A)): pass # E: Metaclasses not inheriting from "type" are not supported
4977+
@six.add_metaclass(A) # E: Metaclasses not inheriting from "type" are not supported \
49784978
# E: Argument 1 to "add_metaclass" has incompatible type "Type[A]"; expected "Type[type]"
49794979

49804980
class D3(A): pass
49814981
class C4(six.with_metaclass(M), metaclass=M): pass # E: Multiple metaclass definitions
49824982
@six.add_metaclass(M)
49834983
class D4(metaclass=M): pass # E: Multiple metaclass definitions
4984-
class C5(six.with_metaclass(f())): pass # E: Dynamic metaclass not supported for 'C5'
4985-
@six.add_metaclass(f()) # E: Dynamic metaclass not supported for 'D5'
4984+
class C5(six.with_metaclass(f())): pass # E: Dynamic metaclass not supported for "C5"
4985+
@six.add_metaclass(f()) # E: Dynamic metaclass not supported for "D5"
49864986
class D5: pass
49874987

49884988
@six.add_metaclass(M)
@@ -4991,8 +4991,8 @@ class CD(six.with_metaclass(M)): pass # E: Multiple metaclass definitions
49914991
class M1(type): pass
49924992
class Q1(metaclass=M1): pass
49934993
@six.add_metaclass(M)
4994-
class CQA(Q1): pass # E: Inconsistent metaclass structure for 'CQA'
4995-
class CQW(six.with_metaclass(M, Q1)): pass # E: Inconsistent metaclass structure for 'CQW'
4994+
class CQA(Q1): pass # E: Inconsistent metaclass structure for "CQA"
4995+
class CQW(six.with_metaclass(M, Q1)): pass # E: Inconsistent metaclass structure for "CQW"
49964996
[builtins fixtures/tuple.pyi]
49974997

49984998
[case testSixMetaclassErrors_python2]
@@ -5105,13 +5105,13 @@ class A(object): pass
51055105
def f() -> type: return M
51065106
class C1(future.utils.with_metaclass(M), object): pass # E: Unsupported dynamic base class "future.utils.with_metaclass"
51075107
class C2(C1, future.utils.with_metaclass(M)): pass # E: Unsupported dynamic base class "future.utils.with_metaclass"
5108-
class C3(future.utils.with_metaclass(A)): pass # E: Metaclasses not inheriting from 'type' are not supported
5108+
class C3(future.utils.with_metaclass(A)): pass # E: Metaclasses not inheriting from "type" are not supported
51095109
class C4(future.utils.with_metaclass(M), metaclass=M): pass # E: Multiple metaclass definitions
5110-
class C5(future.utils.with_metaclass(f())): pass # E: Dynamic metaclass not supported for 'C5'
5110+
class C5(future.utils.with_metaclass(f())): pass # E: Dynamic metaclass not supported for "C5"
51115111

51125112
class M1(type): pass
51135113
class Q1(metaclass=M1): pass
5114-
class CQW(future.utils.with_metaclass(M, Q1)): pass # E: Inconsistent metaclass structure for 'CQW'
5114+
class CQW(future.utils.with_metaclass(M, Q1)): pass # E: Inconsistent metaclass structure for "CQW"
51155115
[builtins fixtures/tuple.pyi]
51165116

51175117
[case testFutureMetaclassErrors_python2]

test-data/unit/check-newsemanal.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ reveal_type(A.f()) # N: Revealed type is "builtins.int"
11371137
class A(metaclass=B):
11381138
pass
11391139

1140-
class AA(metaclass=C): # E: Metaclasses not inheriting from 'type' are not supported
1140+
class AA(metaclass=C): # E: Metaclasses not inheriting from "type" are not supported
11411141
pass
11421142

11431143
class B(type):
@@ -1284,7 +1284,7 @@ class A:
12841284
__metaclass__ = B
12851285

12861286
class AA:
1287-
__metaclass__ = C # E: Metaclasses not inheriting from 'type' are not supported
1287+
__metaclass__ = C # E: Metaclasses not inheriting from "type" are not supported
12881288

12891289
class B(type):
12901290
def f(cls):

test-data/unit/check-python2.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class M(type):
301301

302302
[case testDynamicMetaclass]
303303
class C(object):
304-
__metaclass__ = int() # E: Dynamic metaclass not supported for 'C'
304+
__metaclass__ = int() # E: Dynamic metaclass not supported for "C"
305305

306306
[case testMetaclassDefinedAsClass]
307307
class C(object):

test-data/unit/fine-grained.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,7 +3050,7 @@ class M(type):
30503050
pass
30513051
[out]
30523052
==
3053-
a.py:3: error: Inconsistent metaclass structure for 'D'
3053+
a.py:3: error: Inconsistent metaclass structure for "D"
30543054

30553055
[case testFineMetaclassDeclaredUpdate]
30563056
import a
@@ -3066,7 +3066,7 @@ class M(type): pass
30663066
class M2(type): pass
30673067
[out]
30683068
==
3069-
a.py:3: error: Inconsistent metaclass structure for 'D'
3069+
a.py:3: error: Inconsistent metaclass structure for "D"
30703070

30713071
[case testFineMetaclassRemoveFromClass]
30723072
import a
@@ -3128,7 +3128,7 @@ M = 1
31283128
class M(type):
31293129
pass
31303130
[out]
3131-
a.py:2: error: Invalid metaclass 'b.M'
3131+
a.py:2: error: Invalid metaclass "b.M"
31323132
==
31333133

31343134
[case testFixedAttrOnAddedMetaclass]
@@ -3241,7 +3241,7 @@ class M(type):
32413241
M = 1
32423242
[out]
32433243
==
3244-
a.py:2: error: Invalid metaclass 'b.M'
3244+
a.py:2: error: Invalid metaclass "b.M"
32453245

32463246
[case testRefreshGenericSubclass]
32473247
from typing import Generic, TypeVar

test-data/unit/semanal-errors.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ class A(metaclass=abc.Foo): pass # E: Name "abc.Foo" is not defined
999999

10001000
[case testNonClassMetaclass]
10011001
def f(): pass
1002-
class A(metaclass=f): pass # E: Invalid metaclass 'f'
1002+
class A(metaclass=f): pass # E: Invalid metaclass "f"
10031003
[out]
10041004

10051005
[case testInvalidTypevarArguments]

0 commit comments

Comments
 (0)