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

Union with generic types is broken #250

Closed
mvanderlee opened this issue Sep 18, 2023 · 3 comments · Fixed by #260
Closed

Union with generic types is broken #250

mvanderlee opened this issue Sep 18, 2023 · 3 comments · Fixed by #260

Comments

@mvanderlee
Copy link
Contributor

from typing import Union
import marshmallow.fields as mf
from marshmallow_dataclass import NewType, dataclass
from webargs.fields import DelimitedList

DelimitedListInt = NewType('DelimitedListInt', list[int], field=lambda *args, **kwargs: DelimitedList(mf.Integer(), *args, **kwargs))

@dataclass
class Test:
  myint: Union[DelimitedListInt, list[int]]


Test.Schema().load({'myint': '1,2,3'})

Raises:

TypeError: isinstance() argument 2 cannot be a parameterized generic

The issue is that typeguard does a check of isinstance([1, 2, 3], list[int]) which is not allowed.
Updating to typeguard 4.0.0 fixes the issue. I've also verified that the latest version, 4.1.5 works.

@lovasoa
Copy link
Owner

lovasoa commented Sep 18, 2023

Thanks! Can you open a pr ?

@LostInDarkMath
Copy link

@jasle Can you pls submit a PR?

@jasle
Copy link
Contributor

jasle commented May 8, 2024

typeguard 4.0.0 and newer does drop the support for python older than 3.7.4, so it is not possible to fix this for all python versions currently supported by python-marshmallow.

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

Successfully merging a pull request may close this issue.

4 participants