Skip to content

Using the django.core.checks.register makes function untyped #1098

@jaap3

Description

@jaap3

I'm experimenting with type annotations and chose a fairly simple project to add type annotations to (just a couple of additional Django checks). However I ran into the following:

What's wrong

from django.core.checks import register

@register("foo")
def check_foo_is_bar(app_configs: Apps, **kwargs: Any) -> List[Warning]:
    ...

Results in mypy complaining:

Untyped decorator makes function "check_foo_is_bar" untyped

How it should be

The register decorator is currently annotated as returning Any. If somehow it can be annotated as being essentially the same as CheckRegistry.register all would be well (I think). Is that possible?

System information

  • python version: Python 3.8.12
  • django version: 4.1
  • mypy version: 0.961
  • django-stubs version: 1.12.0
  • django-stubs-ext version: 0.5.0

Additional information

It's possible to work around this by using the decorator as a function instead:

def check_foo_is_bar(app_configs: Apps, **kwargs: Any) -> List[Warning]:
    ...

register(check_foo_is_bar, "foo")

But it would be nice if the decorator worked as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions