Skip to content

Commit 2549f71

Browse files
committed
PyYAML: Use TypeAlias to mimic "infinity literal" restriction
#8973 (review)
1 parent e2bd5b1 commit 2549f71

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

stubs/PyYAML/yaml/__init__.pyi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def emit(
4646
Dumper=...,
4747
canonical: bool | None = ...,
4848
indent: int | None = ...,
49-
width: float | None = ...,
49+
width: int | _Inf | None = ...,
5050
allow_unicode: bool | None = ...,
5151
line_break: str | None = ...,
5252
): ...
@@ -57,7 +57,7 @@ def serialize_all(
5757
Dumper=...,
5858
canonical: bool | None = ...,
5959
indent: int | None = ...,
60-
width: float | None = ...,
60+
width: int | _Inf | None = ...,
6161
allow_unicode: bool | None = ...,
6262
line_break: str | None = ...,
6363
encoding: str | None = ...,
@@ -73,7 +73,7 @@ def serialize_all(
7373
Dumper=...,
7474
canonical: bool | None = ...,
7575
indent: int | None = ...,
76-
width: float | None = ...,
76+
width: int | _Inf | None = ...,
7777
allow_unicode: bool | None = ...,
7878
line_break: str | None = ...,
7979
encoding: str | None = ...,
@@ -90,7 +90,7 @@ def serialize(
9090
*,
9191
canonical: bool | None = ...,
9292
indent: int | None = ...,
93-
width: float | None = ...,
93+
width: int | _Inf | None = ...,
9494
allow_unicode: bool | None = ...,
9595
line_break: str | None = ...,
9696
encoding: str | None = ...,
@@ -107,7 +107,7 @@ def serialize(
107107
*,
108108
canonical: bool | None = ...,
109109
indent: int | None = ...,
110-
width: float | None = ...,
110+
width: int | _Inf | None = ...,
111111
allow_unicode: bool | None = ...,
112112
line_break: str | None = ...,
113113
encoding: str | None = ...,
@@ -125,7 +125,7 @@ def dump_all(
125125
default_flow_style: bool | None = ...,
126126
canonical: bool | None = ...,
127127
indent: int | None = ...,
128-
width: float | None = ...,
128+
width: int | _Inf | None = ...,
129129
allow_unicode: bool | None = ...,
130130
line_break: str | None = ...,
131131
encoding: str | None = ...,
@@ -144,7 +144,7 @@ def dump_all(
144144
default_flow_style: bool | None = ...,
145145
canonical: bool | None = ...,
146146
indent: int | None = ...,
147-
width: float | None = ...,
147+
width: int | _Inf | None = ...,
148148
allow_unicode: bool | None = ...,
149149
line_break: str | None = ...,
150150
encoding: str | None = ...,
@@ -164,7 +164,7 @@ def dump(
164164
default_flow_style: bool | None = ...,
165165
canonical: bool | None = ...,
166166
indent: int | None = ...,
167-
width: float | None = ...,
167+
width: int | _Inf | None = ...,
168168
allow_unicode: bool | None = ...,
169169
line_break: str | None = ...,
170170
encoding: str | None = ...,
@@ -184,7 +184,7 @@ def dump(
184184
default_flow_style: bool | None = ...,
185185
canonical: bool | None = ...,
186186
indent: int | None = ...,
187-
width: float | None = ...,
187+
width: int | _Inf | None = ...,
188188
allow_unicode: bool | None = ...,
189189
line_break: str | None = ...,
190190
encoding: str | None = ...,
@@ -203,7 +203,7 @@ def safe_dump_all(
203203
default_flow_style: bool | None = ...,
204204
canonical: bool | None = ...,
205205
indent: int | None = ...,
206-
width: float | None = ...,
206+
width: int | _Inf | None = ...,
207207
allow_unicode: bool | None = ...,
208208
line_break: str | None = ...,
209209
encoding: str | None = ...,
@@ -222,7 +222,7 @@ def safe_dump_all(
222222
default_flow_style: bool | None = ...,
223223
canonical: bool | None = ...,
224224
indent: int | None = ...,
225-
width: float | None = ...,
225+
width: int | _Inf | None = ...,
226226
allow_unicode: bool | None = ...,
227227
line_break: str | None = ...,
228228
encoding: str | None = ...,
@@ -241,7 +241,7 @@ def safe_dump(
241241
default_flow_style: bool | None = ...,
242242
canonical: bool | None = ...,
243243
indent: int | None = ...,
244-
width: float | None = ...,
244+
width: int | _Inf | None = ...,
245245
allow_unicode: bool | None = ...,
246246
line_break: str | None = ...,
247247
encoding: str | None = ...,
@@ -260,7 +260,7 @@ def safe_dump(
260260
default_flow_style: bool | None = ...,
261261
canonical: bool | None = ...,
262262
indent: int | None = ...,
263-
width: float | None = ...,
263+
width: int | _Inf | None = ...,
264264
allow_unicode: bool | None = ...,
265265
line_break: str | None = ...,
266266
encoding: str | None = ...,

stubs/PyYAML/yaml/dumper.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Mapping
22
from typing import Any
3+
from typing_extensions import TypeAlias
34

45
from yaml.emitter import Emitter
56
from yaml.representer import BaseRepresenter, Representer, SafeRepresenter
@@ -8,6 +9,10 @@ from yaml.serializer import Serializer
89

910
from .emitter import _WriteStream
1011

12+
# Ideally, there would be a way to limit these values to only +/- float("inf"),
13+
# but that's not possible at the moment (https://github.com/python/typing/issues/1160).
14+
_Inf: TypeAlias = float
15+
1116
class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
1217
def __init__(
1318
self,
@@ -16,7 +21,7 @@ class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
1621
default_flow_style: bool | None = ...,
1722
canonical: bool | None = ...,
1823
indent: int | None = ...,
19-
width: float | None = ...,
24+
width: int | _Inf | None = ...,
2025
allow_unicode: bool | None = ...,
2126
line_break: str | None = ...,
2227
encoding: str | None = ...,
@@ -35,7 +40,7 @@ class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver):
3540
default_flow_style: bool | None = ...,
3641
canonical: bool | None = ...,
3742
indent: int | None = ...,
38-
width: float | None = ...,
43+
width: int | _Inf | None = ...,
3944
allow_unicode: bool | None = ...,
4045
line_break: str | None = ...,
4146
encoding: str | None = ...,
@@ -54,7 +59,7 @@ class Dumper(Emitter, Serializer, Representer, Resolver):
5459
default_flow_style: bool | None = ...,
5560
canonical: bool | None = ...,
5661
indent: int | None = ...,
57-
width: float | None = ...,
62+
width: int | _Inf | None = ...,
5863
allow_unicode: bool | None = ...,
5964
line_break: str | None = ...,
6065
encoding: str | None = ...,

0 commit comments

Comments
 (0)