Skip to content

d-v-b/tytr

Repository files navigation

tytr

Type transformations for Python.

Create types from class definitions.

Create tests to keep those types up to date.

Type creation

# foo.py
class Foo:
    a: int
    b: float

A TypedDict based on Foo:

$ tytr gen typeddict foo.py::Foo --name FooDict
# Generated by tytr gen typeddict
from __future__ import annotations
from typing_extensions import TypedDict

class FooDict(TypedDict):
    a: int
    b: float

A protocol for a getter for Foo:

$ tytr gen getter foo.py::Foo --name GetFoo
# Generated by tytr gen getter
from __future__ import annotations
from typing import Literal, Protocol, overload

class GetFoo(Protocol):
    @overload
    def __call__(self, key: Literal["a"]) -> int: ...

    @overload
    def __call__(self, key: Literal["b"]) -> float: ...

... and many more

About

Type transformations for Python

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages