Skip to content

aorta.race.modes: PEP 562 __getattr__ with no __dir__, so __all__ names are missing from dir() #448

Description

@amd-vivekag

Found by a sweep while addressing Copilot's __dir__ comment on #428, which
raised the same class of issue against aorta/__init__.py. Filed rather than
folded into #428 because src/aorta/race/ is outside that PR's diff.

src/aorta/race/modes/__init__.py defers three exports behind a module-level
__getattr__ (PEP 562) and has no __dir__:

# Lazy imports to avoid circular dependencies
def __getattr__(name: str):
    if name == "DefaultModeReproducer":
        from .default import DefaultModeReproducer
        return DefaultModeReproducer
    ...

__all__ = [
    "create_reproducer",
    "DefaultModeReproducer",
    "DDPModeReproducer",
    "FSDPModeReproducer",
]

So on a fresh import set(__all__) <= set(dir(aorta.race.modes)) is false:
three of the four promised names are absent from dir() until something has
already read them. Tab-completion and help() do not advertise them, which is
the introspection regression Copilot described on #428.

The repo already has an established form for this, in four modules:

def __dir__() -> list[str]:
    return sorted(set(globals()) | set(__all__))

aorta/race/modes is the only module-level __getattr__ in src/ still
missing it.

What would close this

  1. Add the same __dir__ to src/aorta/race/modes/__init__.py.
  2. A test asserting set(__all__) <= set(dir(...)) on a fresh import in a
    subprocess
    — in-process the pytest session has usually already resolved
    the names, so the assertion passes vacuously. tests/test_package_version.py
    has the pattern.

Low priority: this is introspection only, no import or runtime behaviour
changes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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