Skip to content

Replace data_schema classes with more resilient ones - #2

Open
nonowazu wants to merge 1 commit into
caitlyn-gg:ida9-improvementsfrom
nonowazu:fix/data_schema
Open

Replace data_schema classes with more resilient ones#2
nonowazu wants to merge 1 commit into
caitlyn-gg:ida9-improvementsfrom
nonowazu:fix/data_schema

Conversation

@nonowazu

@nonowazu nonowazu commented Mar 22, 2026

Copy link
Copy Markdown

This changes out all the classes in ida/data_schema.py with dataclasses with several benefits:

  • These are drop-in replacements to the existing classes

  • You avoid a mutable default argument issue with every argument that's foo=[]

    At current, if you instantiate a class with the default, a second class with the default, append to the first instance's list, it will appear in the second instance; default_factory avoids this

  • You get __repr__ for free so if you're examining in the console or just print(foo), you'll get poentially more useful output

  • Not relevant here I don't think, but you get __eq__ for free too

  • Gets rid of # type: comments since python has had relevant types for the classes for probably a decade now

  • Removes a pass in DefinedData that was actually useless

I checked to make sure that nothing is attempting to mutate things like instances as a feature instead of a bug and I didn't see any at first glance.

Obviously, feedback etc appreciated.

This changes out all the classes in `ida/data_schema.py` with dataclasses with several benefits:

* These are drop-in replacements to the existing classes
* You avoid a multable default argument issue with every argument that's `foo=[]`

    At current, if you instantate a class with the default, a second class with the default, append to the first instance's list, it will appear in the second instance; `default_factory` avoids this

* You get `__repr__` for free so if you're examining in the console or just `print(foo)`, you'll get poentially more useful output
* Not relevant here I don't think, but you get `__eq__` for free too
* Gets rid of `# type:` comments since python has had relevant types for the classes for probably a decade now
* Removes a `pass` in `DefinedData` that was actually useless

I checked to make sure that nothing is attempting to mutate things like `instances` as a feature instead of a bug and I didn't see any at first glance.
@nonowazu

Copy link
Copy Markdown
Author

As a note, if you don't accept this PR (perfectly fine - your repo and all), at least fix the mutable shared default by swapping it out with

def __init__(self, some_arg: list[X] = []):
    self.some_arg = some_arg

With something like

def __init__(self, some_arg: Optional[list[X]] = None):
    self.some_arg = some_arg if some_arg is not None else []

The reason for the gross ternary here is because some people may pass a (falsy) list reference expecting to be able to mutate that upstream reference and get it for free in the object.

@nonowazu
nonowazu changed the base branch from main to ida9-improvements March 22, 2026 14:35
@nonowazu nonowazu changed the title Replace data_schema classes with more resiliant ones Replace data_schema classes with more resilient ones Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant