-
Notifications
You must be signed in to change notification settings - Fork 241
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
Ability to disallow specific types for a TypeVar #599
Comments
I don't think that there's a way to do this. I'll leave this issue open as a potential new feature, though it seems low priority unless perhaps we can find additional use cases. |
Ok, thanks. If something like that does end up becoming a feature, let me know if there's anything I can do to help. |
New use case: disallow nesting a type into itself for flat dicts.
Here is an example of flat dict (FlatHyperparams):
And a nested dict (DictHyperparams)
Source code: https://github.com/Neuraxio/Neuraxle/blob/0.1/neuraxle/typing.py |
#614 is also related. It seems to there was an issue for |
Here is a use case I'm interested in (very similar to what is described in #614) A function that wraps the argument in a list - unless the type is already a list This is what I would like to have - except I can't communicate "anything else" to MyPy ListOrTuple = TypeVar("ListOrTuple", List, Tuple)
AnythingElse = TypeVar("AnythingElse")
@overload
def as_list(val: ListOrTuple) -> ListOrTuple: ...
@overload
def as_list(val: AnythingElse) -> List[AnythingElse]: ...
def as_list(val):
return val if isinstance(val, (list, tuple)) else [val] |
Same thing led me here. https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/lib.pyi#L37 |
Closing as a more specific variant of #801. |
Couldn't find any discussions on this, but it would be convenient to be able to specify some types to not be allowed for a TypeVar. For example to be able to say:
A motivating example is the following:
where T shouldn't be an Exception.
SO post: https://stackoverflow.com/questions/53696345/disallow-specific-types-for-a-typevar-in-python
The text was updated successfully, but these errors were encountered: