KEMBAR78
Plugin generated methods are reported with `explicit-override` error enabled · Issue #17417 · python/mypy · GitHub
Skip to content

Plugin generated methods are reported with explicit-override error enabled #17417

@sobolevn

Description

@sobolevn

In django-stubs we are using common.add_method to add some methods that are generated in runtime for some django fields. For example, DateField generates get_next_by_FIELD_NAME.

Source: https://github.com/django/django/blob/72b7aecbbfbec0ceb1a829eef82a68d7283df604/django/db/models/fields/__init__.py#L1515-L1531
Plugin: https://github.com/typeddjango/django-stubs/blob/23530b96dd17efa1eb9961c86894fb734658ee0d/mypy_django_plugin/transformers/models.py#L591-L621

So, when there are several mixins that both provide the same method (django models use mixins quite often), then there are very annoying false-positives:

server/apps/identity/models.py:57: error: Method "get_next_by_created_at" is not using @override but is overriding a method in class "server.common.django.models.TimedMixin"  [explicit-override]
server/apps/identity/models.py:57: error: Method "get_previous_by_created_at" is not using @override but is overriding a method in class "server.common.django.models.TimedMixin"  [explicit-override]
server/apps/identity/models.py:57: error: Method "get_next_by_updated_at" is not using @override but is overriding a method in class "server.common.django.models.TimedMixin"  [explicit-override]
server/apps/identity/models.py:57: error: Method "get_previous_by_updated_at" is not using @override but is overriding a method in class "server.common.django.models.TimedMixin"  [explicit-override]

It took me quite some time to understand what is going on there.

I propose to add a new flag to common.add_method, which will set explicit_override by default.

Metadata

Metadata

Assignees

Labels

bugmypy got something wrongfalse-positivemypy gave an error on correct codetopic-pluginsThe plugin API and ideas for new plugins

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions