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

Signature of "has_add_permission" incompatible with supertype "BaseModelAdmin" #203

Closed
Sukochev opened this issue Oct 7, 2019 · 2 comments · Fixed by #205
Closed

Signature of "has_add_permission" incompatible with supertype "BaseModelAdmin" #203

Sukochev opened this issue Oct 7, 2019 · 2 comments · Fixed by #205
Assignees
Labels
bug Something isn't working

Comments

@Sukochev
Copy link

Sukochev commented Oct 7, 2019

What's wrong

Getting mypy error:
project/contact/admin.py:25: error: Signature of "has_add_permission" incompatible with supertype "BaseModelAdmin"

For example in registering a custom Django Admin such as

class ContactAdmin(admin.ModelAdmin):
    list_display = ("__str__",)

    def has_add_permission(self, request: HttpRequest) -> bool:
        return False

admin.site.register(Contact, ContactAdmin)

results in the error above for the method has_add_permission.

This is possibly due to the fact that

def has_add_permission(self, request: HttpRequest, obj: Optional[Model] = ...) -> bool: ...

has def has_add_permission(self, request: HttpRequest, obj: Optional[Model] = ...) -> bool: ...

while https://github.com/django/django/blob/42b9a23267f14be39b9b00958e18d5746783208e/django/contrib/admin/options.py#L467

has def has_add_permission(self, request):

i.e obj parameter shouldn't be in stub?

How is that should be

I don't think this error should appear here. The case of has_change_permission for example, works as expected.

System information

  • OS:
  • python version: 3.7.3
  • django version: 2.2.5
  • mypy version: 0.720
  • django-stubs version: 1.1.0
@Sukochev Sukochev added the bug Something isn't working label Oct 7, 2019
@sobolevn
Copy link
Member

sobolevn commented Oct 8, 2019

Yes, looks like a bug in stubs. @Sukochev can you please send a PR with the fix?

@Sukochev
Copy link
Author

Sukochev commented Oct 8, 2019

@sobolevn Sure, will do.

AndreyMZ pushed a commit to AndreyMZ/django-stubs that referenced this issue Oct 11, 2019
sobolevn pushed a commit that referenced this issue Oct 11, 2019
…205)

* Fix `django.contrib.admin.options.BaseModelAdmin.has_add_permission` (#203).

* Add `django.db.models.base.Model.unique_error_message` (#204).
voidus pushed a commit to voidus/django-stubs that referenced this issue Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants