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

refactor: consider using method overload #15

Open
inspiralpatterns opened this issue Jul 12, 2023 · 0 comments
Open

refactor: consider using method overload #15

inspiralpatterns opened this issue Jul 12, 2023 · 0 comments

Comments

@inspiralpatterns
Copy link
Collaborator

def generate(
self, docs: Union[VectorDoc, list[VectorDoc]]
) -> Union[VectorDoc, list[VectorDoc]]:

I am not a fan of functions that can return either one or the other type, however, I assume that given a List[VectorDoc], generate will always return a List[VectorDoc]. If so, then you can use the @overload decorator and declare two function signatures:

from typing import overload

@overload
def generate(docs: VectorDoc) -> VectorDoc:
    ...

@overload
def generate(docs: List[VectorDoc]) -> List[VectorDoc]:
    ...

def generate(x):
    # here goes the implementation

Note that the ellipsis ... is required.

@stoyan-stoyanov stoyan-stoyanov self-assigned this Jul 14, 2023
@stoyan-stoyanov stoyan-stoyanov removed their assignment Jul 28, 2023
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