art049 / odmantic

Sync and Async ODM (Object Document Mapper) for MongoDB based on python type hints
http://art049.github.io/odmantic
ISC License
1.01k stars 95 forks source link

Incompatible With Type Hinting Generics In Standard Collections #66

Closed songzhi closed 1 year ago

songzhi commented 3 years ago
from odmantic import Model

class User(Model):
    scopes: list[str]

print(User(scopes=[]))

Caused errors like this:

Traceback (most recent call last):
  File "C:\xxxx\main.py", line 3, in <module>
    class User(Model):
  File "C:\xxxx\lib\site-packages\odmantic\model.py", line 381, in __new__
    mcs.__validate_cls_namespace__(name, namespace)
  File "C:\xxxx\lib\site-packages\odmantic\model.py", line 219, in __validate_cls_namespace__
    substituted_type = validate_type(field_type)
  File "C:\xxxx\lib\site-packages\odmantic\model.py", line 176, in validate_type
    setattr(type_, "__args__", new_arg_types)
AttributeError: readonly attribute
MatthewNewland commented 1 year ago

This is a blocking bug for me--I cannot use odmantic until it's resolved. I guess I've got to use Beanie instead.