Specify Python type scenarios on a function

Viewed 44

I would like to have a mypy-accepted constructor, based on this example:

N = Union[Network4, Network6]
A = Union[Address4, Address6]

class Foo:
    def __init__(self, network: N, address: A) -> None:
        self.network: N = network
        self.address: A = address

As you see in this example, you can mix the IPv4 and IPv6 in one call, but I want to accept the appropriate pairs only.

Can I, and how can I describe that with pure type-hinting (without @overload)?

0 Answers
Related