Skip to content

Error when setting gettext_lazy as class attribute #1231

@browniebroke

Description

@browniebroke

Bug report

What's wrong

We received an update in cookiecutter-django to update to the latest django-stubs, but the type checks fail:

https://github.com/cookiecutter/cookiecutter-django/actions/runs/3385553002/jobs/5623835120#step:5:2492

The reason is because the success_message attribute for SuccessMessageMixin should accept lazy string.

class SuccessMessageMixin:
success_message: str = ...
def form_valid(self, form: BaseForm) -> HttpResponse: ...
def get_success_message(self, cleaned_data: Dict[str, str]) -> str: ...

References:

I assume there are a other mixin with the same problem.

Related error:

Note that the CI run above also have a similar error regarding the model admin fieldsets attribute (defined here) - I'm happy to open a separate issue about it, but maybe we should consider a overall fix?

How is that should be

The type annotation for success_message should accept lazy strings too:

class SuccessMessageMixin: 
     success_message: _StrOrPromise = ... 

System information

  • OS:
  • python version: 3.10
  • django version: 4.0
  • mypy version: 0.982
  • django-stubs version: 1.13.0
  • django-stubs-ext version: n/a (I don't think this package is installed?)

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