Skip to content

Graphik defines __init__ twice, so the no-argument constructor is dead code #20

Description

@dmccoystephenson

Summary

graphik.py defines __init__ twice on the Graphik class. The first definition (graphik.py:14-19) takes no arguments and creates its own 900x600 display via pygame.display.set_mode(...). The second definition (graphik.py:21-24) takes a gameDisplay argument. Python binds only the last definition, so the no-argument form is silently discarded — it is dead code that reads as though it were a supported way to construct the class.

Verification

The behavior was confirmed against the source in this repository under SDL_VIDEODRIVER=dummy:

init defs in source: 2
bound init signature: (self, gameDisplay)
no-arg construction raises TypeError: __init__() missing 1 required positional argument: 'gameDisplay'

main.py:51 is the only in-tree caller, and it passes a display, so no runtime behavior depends on the shadowed definition today.

Why it matters

Python has no constructor overloading. A reader of graphik.py is invited to believe Graphik() is valid, and any future caller written against that reading fails with a TypeError. The displayWidth / displayHeight locals in the shadowed definition also mislead, since they never take effect.

Suggested resolution

Either of the following would resolve the ambiguity:

  • Delete the shadowed no-argument definition, leaving __init__(self, gameDisplay) as the single documented constructor.
  • Merge the two into one definition with a default, e.g. __init__(self, gameDisplay=None), where a None display causes the 900x600 surface to be created. This preserves the apparent intent of the first definition, but couples Graphik to display creation, which RenderWindow (see Create a RenderWindow class to manage Pygame initialization #6) is intended to own.

Deleting the shadowed definition is the lower-risk option and is the one recommended here.

Acceptance criteria

  • graphik.py contains exactly one def __init__ on the Graphik class.
  • Whatever construction forms remain are exercised by a unit test under tests/ with pygame mocked, so no display is required.

This issue body was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

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