Expose IcPin side Literal type

Issue #53 resolved
John Hagen created an issue

mypy users utilizing mypy could benefit from the Literal types being exposed to them.

For example:

@dataclass
class IcPin:
    ...
    side: Literal['left', 'right', 'top', 'bottom', 'L', 'R', 'T', 'B'] = 'L'
    ...

Ideally the type Literal['left', 'right', 'top', 'bottom', 'L', 'R', 'T', 'B'] should be exposed as a module type that can be imported. This allows users who pass in a side to properly annotate it and error mypy errors such as:

main.py:20: error: Argument "side" to "IcPin" has incompatible type "str"; expected "Union[Literal['left'], Literal['right'], Literal['top'], Literal['bottom'], Literal['L'], Literal['R'], Literal['T'], Literal['B']]"

This could be defined as:

IcSide = Literal["left", "right", "top", "bottom", "L", "R", "T", "B"]

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

Comments (7)

  1. John Hagen reporter

    schemdraw.types has a Side type but it is not exactly the same definition. If a user tries to use it, they get this error:

    error: Argument "side" to "IcPin" has incompatible type "Union[Literal['top'], Literal['bot'], Literal['lft'], Literal['rgt'], Literal['bottom'], Literal['left'], Literal['right']]"; expected "Union[Literal['left'], Literal['right'], Literal['top'], Literal['bottom'], Literal['L'], Literal['R'], Literal['T'], Literal['B']]"
    

    Perhaps the Side types should be unified, or a new IcSide type should be created.

  2. Log in to comment