Expose IcPin side Literal type
Issue #53
resolved
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)
-
reporter -
reporter - edited description
-
reporter - edited description
-
reporter - changed title to Expose IcPin side Literal type
-
repo owner The schemdraw.types.Side type can now be used for both labels and IcPins (
e67f65b
). -
reporter @cdelker Would you be able to publish another PyPI release that includes this? Thanks.
-
repo owner - changed status to resolved
Done. Just released 0.12.
- Log in to comment
schemdraw.types
has aSide
type but it is not exactly the same definition. If a user tries to use it, they get this error:Perhaps the
Side
types should be unified, or a newIcSide
type should be created.