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

typing support #107

Open
prokoptsev opened this issue Aug 3, 2020 · 4 comments
Open

typing support #107

prokoptsev opened this issue Aug 3, 2020 · 4 comments

Comments

@prokoptsev
Copy link

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
Copy link
Owner

crccheck commented Aug 3, 2020

I've been ignoring these because type support for that scenario has been bad. There's a lot of discussion around this at python/mypy#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
Copy link
Author

Thank you for answer. Can I somehow help?

@crccheck
Copy link
Owner

crccheck commented Aug 4, 2020

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 added a commit that referenced this issue Aug 5, 2020
BREAKING CHANGE: drop Python 3.4 support in preparation for adding type hints and Django 3.1 support

Prereq for #107
@crccheck
Copy link
Owner

python/mypy#708 was closed, so this is worth looking at again

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

@crccheck crccheck pinned this issue Aug 16, 2022
crccheck pushed a commit that referenced this issue Nov 7, 2022
… the admin method (#141)

Add an `@action` decorator that behave's like Django's `admin.action` decorator[^1] to clean up customizing object actions.

[closes #115](#115)

Also relates to #107

[^1]: https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#django.contrib.admin.action
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

2 participants