mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 12:44:29 +08:00
Fix type annotations for django.utils.safestring (#179)
* Add/fix types for django.utils.safestring.mark_safe
Django code ref: 964dd4f4f2/django/utils/safestring.py (L71-L84)
* add generic annotations for mark_safe, remove SafeBytes as it is basically deprecated
Co-authored-by: Daniel Hahler <github@thequod.de>
This commit is contained in:
@@ -39,4 +39,24 @@
|
||||
# Ensure that the method's type is preserved
|
||||
reveal_type(ClassWithAtomicMethod().atomic_method1) # N: Revealed type is 'def (abc: builtins.int) -> builtins.str'
|
||||
# Ensure that the method's type is preserved
|
||||
reveal_type(ClassWithAtomicMethod().atomic_method3) # N: Revealed type is 'def (myparam: builtins.str) -> builtins.int'
|
||||
reveal_type(ClassWithAtomicMethod().atomic_method3) # N: Revealed type is 'def (myparam: builtins.str) -> builtins.int'
|
||||
|
||||
|
||||
- case: mark_safe_decorator_and_function
|
||||
main: |
|
||||
from django.utils.safestring import mark_safe
|
||||
s = 'hello'
|
||||
reveal_type(mark_safe(s)) # N: Revealed type is 'django.utils.safestring.SafeText'
|
||||
reveal_type(mark_safe(s) + mark_safe(s)) # N: Revealed type is 'django.utils.safestring.SafeText'
|
||||
reveal_type(s + mark_safe(s)) # N: Revealed type is 'builtins.str'
|
||||
|
||||
s += mark_safe(s)
|
||||
reveal_type(s) # N: Revealed type is 'builtins.str'
|
||||
ms = mark_safe(s)
|
||||
ms += mark_safe(s)
|
||||
reveal_type(ms) # N: Revealed type is 'django.utils.safestring.SafeText'
|
||||
|
||||
@mark_safe
|
||||
def func(s: str) -> str:
|
||||
pass
|
||||
reveal_type(func) # N: Revealed type is 'def (s: builtins.str) -> builtins.str'
|
||||
|
||||
Reference in New Issue
Block a user