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
Improve handling of long numbers, strings and bytes (#351)
Currently, we allow this:
```py
from typing_extensions import Literal
foo: Literal[1000000000000000000000000000000000000000]
```
But we disallow this:
```python
from typing_extensions import Final
foo: Final = 1000000000000000000000000000000000000000
```
This seems pretty inconsistent; the rationale for disallowing the latter
applies equally well to the former. Fixing this inconsistency also
allows us to clean up the code somewhat.
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,8 @@ currently emitted:
85
85
| Y050 | Prefer `typing_extensions.Never` over `typing.NoReturn` for argument annotations. This is a purely stylistic choice in the name of readability.
86
86
| Y051 | Y051 detects redundant unions between `Literal` types and builtin supertypes. For example, `Literal[5]` is redundant in the union `int \| Literal[5]`, and `Literal[True]` is redundant in the union `Literal[True] \| bool`.
87
87
| Y052 | Y052 disallows assignments to constant values where the assignment does not have a type annotation. For example, `x = 0` in the global namespace is ambiguous in a stub, as there are four different types that could be inferred for the variable `x`: `int`, `Final[int]`, `Literal[0]`, or `Final[Literal[0]]`. Enum members are excluded from this check, as are various special assignments such as `__all__` and `__match_args__`.
88
+
| Y053 | Only string and bytes literals <=50 characters long are permitted.
89
+
| Y054 | Only numeric literals with a string representation <=10 characters long are permitted.
88
90
89
91
Note that several error codes recommend using types from `typing_extensions` or
90
92
`_typeshed`. Strictly speaking, these packages are not part of the standard
Copy file name to clipboardExpand all lines: tests/attribute_annotations.pyi
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -54,10 +54,10 @@ field22: Final = {"foo": 5} # Y015 Only simple default values are allowed for a
54
54
field23="foo"+"bar"# Y015 Only simple default values are allowed for assignments
55
55
field24=b"foo"+b"bar"# Y015 Only simple default values are allowed for assignments
56
56
field25=5*5# Y015 Only simple default values are allowed for assignments
57
-
field26: int=0xFFFFFFFFF# Y015 Only simple default values are allowed for assignments
58
-
field27: int=12345678901# Y015 Only simple default values are allowed for assignments
59
-
field28: int=-0xFFFFFFFFF# Y015 Only simple default values are allowed for assignments
60
-
field29: int=-12345678901# Y015 Only simple default values are allowed for assignments
57
+
field26: int=0xFFFFFFFFF# Y054 Numeric literals with a string representation >10 characters long are not permitted
58
+
field27: int=12345678901# Y054 Numeric literals with a string representation >10 characters long are not permitted
59
+
field28: int=-0xFFFFFFFFF# Y054 Numeric literals with a string representation >10 characters long are not permitted
60
+
field29: int=-12345678901# Y054 Numeric literals with a string representation >10 characters long are not permitted
61
61
62
62
classFoo:
63
63
field1: int
@@ -98,10 +98,10 @@ class Foo:
98
98
field24="foo"+"bar"# Y015 Only simple default values are allowed for assignments
99
99
field25=b"foo"+b"bar"# Y015 Only simple default values are allowed for assignments
100
100
field26=5*5# Y015 Only simple default values are allowed for assignments
101
-
field27=0xFFFFFFFFF# Y015 Only simple default values are allowed for assignments
102
-
field28=12345678901# Y015 Only simple default values are allowed for assignments
103
-
field29=-0xFFFFFFFFF# Y015 Only simple default values are allowed for assignments
104
-
field30=-12345678901# Y015 Only simple default values are allowed for assignments
101
+
field27=0xFFFFFFFFF# Y052 Need type annotation for "field27" # Y054 Numeric literals with a string representation >10 characters long are not permitted
102
+
field28=12345678901# Y052 Need type annotation for "field28" # Y054 Numeric literals with a string representation >10 characters long are not permitted
103
+
field29=-0xFFFFFFFFF# Y052 Need type annotation for "field29" # Y054 Numeric literals with a string representation >10 characters long are not permitted
104
+
field30=-12345678901# Y052 Need type annotation for "field30" # Y054 Numeric literals with a string representation >10 characters long are not permitted
deff37(x: str="a_very_long_stringgggggggggggggggggggggggggggggggggggggggggggggg") ->None: ... # Y011 Only simple default values allowed for typed arguments
66
-
deff38(x: bytes=b"a_very_long_byte_stringggggggggggggggggggggggggggggggggggggg") ->None: ... # Y011 Only simple default values allowed for typed arguments
65
+
deff37(x: str="a_very_long_stringgggggggggggggggggggggggggggggggggggggggggggggg") ->None: ... # Y053 String and bytes literals >50 characters long are not permitted
66
+
deff38(x: bytes=b"a_very_long_byte_stringggggggggggggggggggggggggggggggggggggg") ->None: ... # Y053 String and bytes literals >50 characters long are not permitted
67
+
68
+
foo: str="a_very_long_stringgggggggggggggggggggggggggggggggggggggggggggggg"# Y053 String and bytes literals >50 characters long are not permitted
69
+
bar: bytes=b"a_very_long_byte_stringggggggggggggggggggggggggggggggggggggg"# Y053 String and bytes literals >50 characters long are not permitted
0 commit comments