PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

Proper way to specify type annotation of a MapAttribute subclass?

Open andrewli1030 opened this issue 4 years ago • 3 comments

Supposed I define a MapAttribute subclass like follows:

class MyMapAttribute(MapAttribute):
    pass

When I run pre-commit's (rev 2.1.0) mypy hook (rev 0.701), I run into the following error:

error: Missing type parameters for generic type

I am using pynamodb==4.0.0.

andrewli1030 avatar Aug 19 '19 21:08 andrewli1030

This is happening because the disallow_any_generics is enabled in your mypy conf. The way we currently type MapAttributes is flawed due to it behaving differently depending on whether you subclass it or instantiate it directly. So basically this is a bug in our type information, but not easy to fix today.

@jpinner-lyft do you think it's worth creating a new issue to track the Model/MapAttribute changes that you had lined up?

garrettheel avatar Aug 21 '19 15:08 garrettheel

Do you have any hints on how to type result = MapAttribute(…)? Edit: Separate issue

l0b0 avatar Mar 12 '21 03:03 l0b0

@l0b0 would you mind creating a separate issue with more context?

garrettheel avatar Mar 12 '21 15:03 garrettheel