You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Type the return value of lazy translation functions as Promise.
The return value of the lazy translation functions is a proxied
`Promise` object.
https://github.com/django/django/blob/3.2.6/django/utils/translation/__init__.py#L135-L221.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
* Mark unicode translation functions for deprecation.
https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
* Add proxied functions for Promise.
Although there is nothing defined in `Promise` itself, the only
instances of `Promise` are created by the `lazy` function, with magic
methods defined on it.
https://github.com/django/django/blob/3.2.6/django/utils/functional.py#L84-L191.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
* Add _StrPromise as a special type for Promise objects for str.
This allows the user to access methods defined on lazy strings while
still letting mypy be aware of that they are not instances of `str`.
The definitions for some of the magic methods are pulled from typeshed. We need
those definitions in the stubs so that `_StrPromise` objects will work properly
with operators, as refining operator types is tricky with the mypy
plugins API.
The rest of the methods will be covered by an attribute hook.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
* Implement _StrPromise attribute hook.
This implements an attribute hook that provides type information for
methods that are available on `builtins.str` for `_StrPromise` except
the supported operators. This allows us to avoid copying stubs from the
builtins for all supported methods on `str`.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
* Allow message being a _StrPromise object for RegexValidator.
One intended usage of lazystr is to postpone the translation of the
error message of a validation error. It is possible that we pass a
Promise (specifically _StrPromise) and only evaluate it when a
ValidationError is raised.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
* Refactor _StrPromise attribtue hook with analyze_member_access.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
0 commit comments