sarugaku / plette

Structured Pipfile and Pipfile.lock models.
ISC License
7 stars 7 forks source link

Validation using dataclasses #52

Closed oz123 closed 6 months ago

oz123 commented 7 months ago

This PR replaces the validation with built-in dataclasses validation. The amount of code is reduced significantly, while mostly preserving the API.

The biggest change for the API is that earlier, you could do:

>>>foo = Foo({"a":1, "b":2})
>>>foo.a 
1

Now, you must use unpacking:

>>>foo = Foo(**{"a":1, "b":2})
>>>foo.a
1

Also, I grouped all the models in just one file, as I don't see the point in breaking a file which is ~350 lines long to multiple lines.

All the previous tests are passing, and some new tests are added. Docs are updated too.

Using this version of Plette is going to break things for upstream users (e.g. Pipenv). However, I believe that the only change that these upstream users will need to implement is the unpacking. Users who just use the high level APIs as in plette.pipfiles.Pipfile.load and plette.pipfiles.Pipfile.dump won't see a change.