strawberry
strawberry copied to clipboard
Python 3.9's builtin collections type hints do not work in pydantic types
Python 3.9's builtin collections type hints do not work in pydantic types. Tested with list.
Describe the Bug
Here's the test to reproduce.
Just changed line 219 in tests/experimental/pydantic/test_basic.py
List
-> list
.
def test_list():
class User(pydantic.BaseModel):
friend_names: list[str] # <- List from typings works, but list - does not
@strawberry.experimental.pydantic.type(User)
class UserType:
friend_names: strawberry.auto
definition: TypeDefinition = UserType._type_definition
assert definition.name == "UserType"
[field] = definition.fields
assert field.python_name == "friend_names"
assert isinstance(field.type, StrawberryList)
assert field.type.of_type is str
Got:
E TypeError: issubclass() arg 1 must be a class
System Information
- Operating system: mac oc
- Strawberry version (if applicable): 0.124.0
@benzolium This issue seems to be closely related to #1770 It seems to be an error that occurs after that patch, do you have any ideas?
@na86421 that exact error occurs after that patch indeed, good catch!
Though I've tried to checkout on 2495d0994b25e1e7462e59713bc7ba8b02e3a2f0 (commit before that patch) and it still fails but with another error:
E AttributeError: type object 'list' has no attribute 'copy_with'