papi-web-org / papi-web

Papi-web
7 stars 3 forks source link

Architecture suggestion: delegate class parsing to itself #11

Closed Amaras closed 9 months ago

Amaras commented 11 months ago

I propose making each class responsible for the parsing of itself, in its own little world.

One example for the Tournament class:

class Tournament:
    # Current class definition
    @classmethod
    def from_dict(cls, d: dict):
        # here d is extracted from Event.reader
        # basically (selectively) copy-paste the code of __build_tournament()
        # One caveat is that we need to somehow get the warnings and errors in the correct place
        return cls(...)

This would allow us to test those parts in isolation more easily, e.g. by slicing parts of the file and seeing if it still parses how we want it to

Amaras commented 9 months ago

The current model of using a ThingBuilder works well enough as is. This can be closed.