PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

`ListAttribute(of=UnicodeAttribute)` is not compatible with `List[str]`

Open james10424 opened this issue 1 year ago • 1 comments

They should be equivalent, but mypy/pylance did not agree with this.

To reproduce:

  • create a model with thing = ListAttribute(of=UnicodeAttribute)
  • write this line the_thing: List[str] = model.thing

This seems to be an issue with ListAttribute not properly extracting types, to add to this, consider the following:

the_first_thing: str = model.thing[0] This will cause "UnicodeAttribute" is incompatible with "str"

However, if the attribute is only UnicodeAttribute, then it will be recognized as str when assigned to a variable.

james10424 avatar Jun 06 '24 03:06 james10424

Similarly, when trying to set the array, the same type error is raised.

Argument of type "list[str]" cannot be assigned to parameter "value" of type "List[UnicodeAttribute] | Attribute[List[UnicodeAttribute]]......

james10424 avatar Jun 06 '24 06:06 james10424