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

ListAttribute of NumberAttributes not recognized as float by mypy #1221

Open
jkirsch-patreon opened this issue Jan 16, 2024 · 0 comments
Open

Comments

@jkirsch-patreon
Copy link

When a MapAttribute is defined with an attribute of ListAttribute(of=NumberAttribute), mypy does not recognize the individual elements of the ListAttribute as float. This is not an issue with MapAttributes defined with NumberAttributes.

Example

class ExampleAttribute(MapAttribute):
    ids = ListAttribute(null=False, of=NumberAttribute)


# mypy complains
# No overload variant of "int" matches argument type "NumberAttribute"mypycall-overload
example = ExampleAttribute()
result = [int(x) for x in example.ids]

# reveal_type(x) : NumberAttribute

class MapWithNumber(MapAttribute):
    x = NumberAttribute()


# no issues
m = MapWithNumber()
int(m.x)

pynamodb version: pynamodb==5.5.0
mypy version: 1.8.0
python: 3.9.16

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

No branches or pull requests

1 participant