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

Error when setting gettext_lazy as class attribute #1231

Closed
browniebroke opened this issue Nov 6, 2022 · 2 comments · Fixed by #1233
Closed

Error when setting gettext_lazy as class attribute #1231

browniebroke opened this issue Nov 6, 2022 · 2 comments · Fixed by #1233
Labels
bug Something isn't working

Comments

@browniebroke
Copy link

browniebroke commented Nov 6, 2022

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?)
@browniebroke browniebroke added the bug Something isn't working label Nov 6, 2022
@sobolevn
Copy link
Member

sobolevn commented Nov 6, 2022

CC @PIG208

@sobolevn
Copy link
Member

sobolevn commented Nov 6, 2022

@browniebroke thank you for the report! I think that one issue is fine.

This was pretty big change, I hope we can find and fix corner cases in a patch release soon.

PIG208 added a commit to PIG208/django-stubs that referenced this issue Nov 6, 2022
Fixes typeddjango#1231

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
PIG208 added a commit to PIG208/django-stubs that referenced this issue Nov 6, 2022
Fixes typeddjango#1231

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
sobolevn pushed a commit that referenced this issue Nov 6, 2022
* Replace str with _StrOrPromise where the latter is expected.

Fixes #1231

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Support lazy strings for _FieldsetSpec.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants