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

Allow Promise to be passed to ArrayField.verbose_name #1168

Merged

Conversation

ljodal
Copy link
Contributor

@ljodal ljodal commented Sep 27, 2022

This expands the interface of ArrayField to allow lazy translations to be passed to the verbose_name field. Seems like this was missed in #1139

@@ -27,7 +27,7 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
base_field: Field,
size: Optional[int] = ...,
*,
verbose_name: Optional[Union[str, bytes]] = ...,
verbose_name: Optional[Union[_StrOrPromise, bytes]] = ...,
name: Optional[str] = ...,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should name also accept _StrOrPromise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aight, updated that as well

@@ -27,7 +27,7 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
base_field: Field,
size: Optional[int] = ...,
*,
verbose_name: Optional[Union[str, bytes]] = ...,
verbose_name: Optional[Union[_StrOrPromise, bytes]] = ...,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really in the scope of this PR, but I can't help to ask, why is bytes even allowed here? Makes no sense IMO. Is this for Python 2 compatibility?

The commit message adding this simply states "fixes" d43cb1f (?!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be some legacy thing, I am totally fine with removing it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I can open a PR for that after this is merged, if ljodal doesn't get to it first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the bytes while fixing name :)

@sobolevn
Copy link
Member

Thanks!

@sobolevn sobolevn merged commit 199a7f2 into typeddjango:master Sep 27, 2022
@ljodal ljodal deleted the fix/arrayfield-verbose-name-promise branch September 27, 2022 15:40
@intgr
Copy link
Collaborator

intgr commented Sep 27, 2022

Hrm. The name argument of all other fields is still typed as Optional[str] though.

And I think it doesn't makes sense for Field.name to ever be Promise. It determines the attribute of the Model instance and the database field name, it'll be embedded in migrations and database tables, etc.

@ljodal
Copy link
Contributor Author

ljodal commented Sep 27, 2022

Oh, oops, guess we should revert that bit then 😬

ljodal added a commit to ljodal/django-stubs that referenced this pull request Sep 28, 2022
This was incorrectly changed in typeddjango#1168, so reverting that change.
sobolevn pushed a commit that referenced this pull request Sep 28, 2022
This was incorrectly changed in #1168, so reverting that change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants