connor-makowski / type_enforced

A pure python type enforcer for annotations. Enforce types in python functions and methods.
MIT License
45 stars 2 forks source link

typing.Union[List,str] not supported #18

Closed fenchu closed 1 year ago

fenchu commented 1 year ago
@type_enforced.Enforcer
def update_users_group(myenv:str, group:str, ssn:Union[list,str], op:str='list', access_token:str=None, ok500:bool=True):
    """ add or remove user or a list of users to group """

giving:

FAILED tests/test_02_scim.py/test04_groups[test1] - TypeError: (update_users_group): Type mismatch for typed variable `ssn`. Expected one of the following `[typing.Union[list, str]]` but got `<class 'str'>` instead.

Union Doc

connor-makowski commented 1 year ago

Thanks for creating a ticket and reporting this.

In type_enforced, Union should not be used. Check out the docs here: https://github.com/connor-makowski/type_enforced#getting-started

Specifically:

You can pass multiple types in brackets to validate one of multiple types. For example, you could validate an input was an int or a float with [int, float].

In this case, you should be able to pass in your Union statement simply as a list. EG:

@type_enforced.Enforcer
def update_users_group(myenv:str, group:str, ssn:[list,str], op:str='list', access_token:str=None, ok500:bool=True):
    """ add or remove user or a list of users to group """

Let me know if this does not resolve your issue.

connor-makowski commented 1 year ago

Closing this issue. Feel free to reopen it if you feel that your issue was not handled.

fenchu commented 1 year ago

This works fine, I'm just used to Union[List,str] but easier to write `[list,str] Works great. Thanks