Skip to content

bindings: python: Would type aliases make things easier to read? #150

@vfazio

Description

@vfazio

We can alias types in python, so instead of littering the codebase with complex types like:

dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]]

Or when we move to only support 3.10+:

dict[Iterable[int | str] | int | str, LineSettings | None] 

We can instead do something like:

RequestKey = Union[int, str]
IterableRequestKeys = Iterable[RequestKey]
IterableRequestKeys_or_RequestKey = Union[IterableRequestKeys, RequestKey]

config: dict[IterableRequestKeys_or_RequestKey, Optional[LineSettings]],

The resolved type is equivalent to the previous syntax, but it's maybe a little easier to digest.

https://docs.python.org/3.9/library/typing.html#type-aliases

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions