OpenInterpreter / open-interpreter

A natural language interface for computers
http://openinterpreter.com/
GNU Affero General Public License v3.0
50.66k stars 4.42k forks source link

OpenInterpreter dataclass + constructor unit tests #1214

Closed imapersonman closed 2 months ago

imapersonman commented 2 months ago

Describe the changes you have made:

Changed OpenInterpreter.__init__'s definition to be generated by the @dataclass class annotation. This reduces the number of lines in core.py and makes the initialization code more readable.

There are a couple of wrinkles with this approach.

  1. Fields must have type annotations. The resulting initializer is functionally useless without them. Luckily, this doesn't force the rest of the code to use types.
  2. Fields with mutable defaults must be defined using dataclass's field function with a default_constructor. This could make the two fields that use default_constructor less readable, but I think the short comments I've included clarifies the situation some.

These wrinkles could act as arguments against the use of dataclasses in OI, but I think they're worth it. If we choose no to move forward with the use of dataclasses, I'll break the tests into their own PR.

Pre-Submission Checklist (optional but appreciated):

OS Tests (optional but appreciated):