Skip to content

Commit 766bd38

Browse files
committed
Mostly address review
1 parent 7908bad commit 766bd38

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

mypy/plugins/dataclasses.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ def collect_attributes(self) -> Optional[List[DataclassAttribute]]:
338338
ctx.api.fail(
339339
(
340340
'Type aliases inside dataclass definitions '
341-
'are not supported at runtime.'
341+
'are not supported at runtime'
342342
),
343-
Context(line=node.line, column=node.column)
343+
node
344344
)
345345
# Now do our best to simulate the runtime,
346346
# which treates a TypeAlias definition in a dataclass class
@@ -355,14 +355,9 @@ def collect_attributes(self) -> Optional[List[DataclassAttribute]]:
355355
# Something else -- fallback to Any
356356
else:
357357
var_type = AnyType(TypeOfAny.from_error)
358-
var = Var(name=fullname, type=var_type)
358+
var = Var(name=node.name, type=var_type)
359359
var.info = cls.info
360360
var._fullname = fullname
361-
cls.info.names[fullname] = SymbolTableNode(
362-
kind=MDEF,
363-
node=var,
364-
plugin_generated=True,
365-
)
366361
sym.node = node = var
367362

368363
assert isinstance(node, Var)

test-data/unit/check-dataclasses.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class Foo:
525525

526526
@dataclass
527527
class One:
528-
S: TypeAlias = Foo # E: Type aliases inside dataclass definitions are not supported at runtime.
528+
S: TypeAlias = Foo # E: Type aliases inside dataclass definitions are not supported at runtime
529529

530530
a = One()
531531
b = One(Foo)
@@ -537,7 +537,7 @@ reveal_type(b.S(98)) # N: Revealed type is "__main__.Foo"
537537

538538
@dataclass
539539
class Two:
540-
S: TypeAlias = Callable[[int], str] # E: Type aliases inside dataclass definitions are not supported at runtime.
540+
S: TypeAlias = Callable[[int], str] # E: Type aliases inside dataclass definitions are not supported at runtime
541541

542542
c = Two()
543543
reveal_type(c.S) # N: Revealed type is "Any"

0 commit comments

Comments
 (0)