Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add AnyOf type #7216

Closed
kreid415 opened this issue Jul 15, 2019 · 1 comment
Closed

Feature Request: Add AnyOf type #7216

kreid415 opened this issue Jul 15, 2019 · 1 comment

Comments

@kreid415
Copy link

kreid415 commented Jul 15, 2019

Check that types are a subset of the types passed to AnyOf. When using abstract base classes, this would allow the user to define which types are allowed for inherited classes.
Example:

Base(ABC):
    @ abstractmethod
    def foo(holy_grail: AnyOf[int, str, HolyHandGrenade]) -> None:
        pass

Child_1(Base):
    def foo(holy_grail: int) -> None:
        # implementation

Child_2(Base):
    def foo(holy_grail: str) -> None:
        # implementation 

Child_3(Base):
    def foo(holy_grail: Union[str, int]) -> None:
        # implementation
@JukkaL
Copy link
Collaborator

JukkaL commented Jul 17, 2019

A similar feature has been proposed before, and I agree that it could be useful sometimes. It's not very likely to be supported (soon), since a full implementation would be a lot of work.

Closing as essentially a duplicate of python/typing#566. Feel free to continue the discussion there, as your use case is a little different from the existing examples.

@JukkaL JukkaL closed this as completed Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants