Skip to content

Is the _HAS_DEFAULT_FACTORY here expected? #2808

@yueyinqiu

Description

@yueyinqiu

The following code outputs a _HAS_DEFAULT_FACTORY, which doesn't seem to be what I expected:

import astroid

node = astroid.parse(
    """
    from dataclasses import dataclass

    @dataclass
    class A:
        pass
    """)

print(node.locals)
# {'A': [<ClassDef.A l.5 at 0x26f9601b7a0>], 
# 'dataclass': [<ImportFrom l.2 at 0x26f953f3ed0>], 
# '_HAS_DEFAULT_FACTORY': [<AssignName._HAS_DEFAULT_FACTORY l.1 at 0x26f9603ecd0>]}

The _HAS_DEFAULT_FACTORY seems to be related to @dataclass, but I haven't found out why it exists here.

I also tried the following script, and it won't include _HAS_DEFAULT_FACTORY:

from dataclasses import dataclass

@dataclass
class A:
    pass

print(locals().keys())
# dict_keys(['__name__', '__doc__', '__package__', 
# '__loader__', '__spec__', '__annotations__', 
# '__builtins__', '__file__', '__cached__', 
# 'dataclass', 'A'])

(python 3.13.5, astroid 3.3.11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions