ahrefs / atd

Static types for JSON APIs
Other
308 stars 53 forks source link

atdpy: `to_json` and `from_json` incorrect for aliases of `unit` #399

Open kopecs opened 6 months ago

kopecs commented 6 months ago

atdpy translates the atd definition

type t = unit

to

@dataclass
class T:
    """Original type: t"""

    value: None

    @classmethod
    def from_json(cls, x: Any) -> 'T':
        return cls(Unit.from_json(x))

    def to_json(self) -> Any:
        return (lambda x: x.to_json())(self.value)

    @classmethod
    def from_json_string(cls, x: str) -> 'T':
        return cls.from_json(json.loads(x))

    def to_json_string(self, **kw: Any) -> str:
        return json.dumps(self.to_json(), **kw)

However, there is no such class Unit as required by the from_json implementation, and None doesn't have a to_json method, as required by to_json.