Skip to content

should error on dataclasses field but has no type annotation #3262

@asukaminato0721

Description

@asukaminato0721

Describe the Bug

from dataclasses import dataclass, field

@dataclass
class F:
    idx = field(default=1)
    another: int
Traceback (most recent call last):
  File "<python-input-0>", line 3, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib/python3.14/dataclasses.py", line 1442, in dataclass
    return wrap(cls)
  File "/usr/lib/python3.14/dataclasses.py", line 1432, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/usr/lib/python3.14/dataclasses.py", line 1090, in _process_class
    raise TypeError(f'{name!r} is a field but has no type annotation')
TypeError: 'idx' is a field but has no type annotation

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions