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

Fix TypeError for GenericModel with Callable param #4653

Merged
merged 2 commits into from Oct 31, 2022

Conversation

mfulgo
Copy link

@mfulgo mfulgo commented Oct 24, 2022

Introduced in 1.10.2, a TypeError would be raised upon creation of a GenericModel class that used a Callable type parameter. This would happen when typing.get_args returned a list for the first type agruments in a Callable and pydantic would try to use the value as a dictionary key. To avoid the issue, we convert the list to a tuple before using it as a key.

The possible approach of modifying pydantic's get_args function to return a tuple instead of a list didn't work out because the return values are used in more places, some of which expect the list and not a tuple.

Fixes #4551

Introduced in 1.10.2, a TypeError would be raised upon creation of a
GenericModel class that used a Callable type parameter. This would
happen when `typing.get_args` returned a list for the first type
agruments in a Callable and pydantic would try to use the value as a
dictionary key. To avoid the issue, we convert the list to a tuple
before using it as a key.

The possible approach of modifying pydantic's `get_args` function to
return a tuple instead of a list didn't work out because the return
values are used in more places, some of which expect the list and not a
tuple.

Fixes pydantic#4551
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM.

changes/4551-mfulgo.md Outdated Show resolved Hide resolved
@samuelcolvin samuelcolvin merged commit 83cf464 into pydantic:1.10.X-fixes Oct 31, 2022
@samuelcolvin
Copy link
Member

thanks so much.

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 this pull request may close these issues.

None yet

2 participants