crccheck / django-object-actions

A Django app for easily adding object tools in the Django admin
https://pypi.org/project/django-object-actions/
Apache License 2.0
681 stars 82 forks source link

typing support #107

Open prokoptsev opened 4 years ago

prokoptsev commented 4 years ago

Hi! How to make library friends with mypy? For example if I use code from readme

class MyModelAdmin(DjangoObjectActions, admin.ModelAdmin):
    def toolfunc(self, request: HttpRequest, obj: MyModel) -> None:
        pass
    toolfunc.label = "This will be the label of the button"
    toolfunc.short_description = "This will be the tooltip of the button"

I catch this error from mypy:

"Callable[[MyModelAdmin, HttpRequest, MyModel], None]" has no attribute "label"
"Callable[[MyModelAdmin, HttpRequest, MyModel], None]" has no attribute "short_description"

For example for django admin short_description and etc. I use django-admin-display. How do you look at adding something like this to your project?

crccheck commented 4 years ago

I've been ignoring these because type support for that scenario has been bad. There's a lot of discussion around this at https://github.com/python/mypy/issues/708

Cannot assign to field of Callable type

I haven't put a lot of effort into this yet because I've been too lazy to break Python 3.4 support (typing wasn't introduced until Python 3.5) There's not a great reason for me to hold onto supporting old versions though so I can give this another shot when I have time.

prokoptsev commented 4 years ago

Thank you for answer. Can I somehow help?

crccheck commented 4 years ago

hmm, I can do a 3.0 release that drops Python 3.4, then we can start adding type hints. I can probably get that done this week.

crccheck commented 2 years ago

https://github.com/python/mypy/issues/708 was closed, so this is worth looking at again

The PR has some examples: https://github.com/python/mypy/pull/13400/files