Skip to content

Bug in dataclass naming #102775

Closed
Closed
@joaopfg

Description

@joaopfg

Hello, quick problem that I had with dataclasses.

I wanted to indicate that some dataclasses of my module are private (just used as fields of the final dataclass), thus prefixing them with __ . Example:

from dataclasses import dataclass, field
@dataclass
class __C:
    c: int

@dataclass
class D:
    d: __C = field(default_factory=__C)

This throws a mysterious:

NameError: name '_D__C' is not defined

Is this a bug ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions