Kevin Murphy
0884fe13d4
PyYAML: Permit width: float for pure-Python dump(...) (#8973)
* PyYAML: Permit `width: float` for pure-Python `dump(...)`
To prevent `PyYAML` from wrapping *any* lines, it's possible to pass
`width=float("inf")`, but the current type hints don't like that. This
works at runtime:
>>> s = yaml.dump({"foo": "bar" * 1000}, width=float("inf"))
>>> print(s)
foo: barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar...
but `mypy` says
floatwidth.py:2: error: No overload variant of "dump" matches argument types "Dict[str, str]", "float"
floatwidth.py:2: note: Possible overload variants:
floatwidth.py:2: note: def dump(data: Any, stream: _WriteStream[Any], Dumper: Any = ..., *, default_style: Optional[str] = ..., default_flow_style: Optional[bool] = ..., canonical: Optional[bool] = ..., indent: Optional[int] = ..., width: Optional[int] = ..., allow_unicode: Optional[bool] = ..., line_break: Optional[str] = ..., encoding: Optional[str] = ..., explicit_start: Optional[bool] = ..., explicit_end: Optional[bool] = ..., version: Optional[Tuple[int, int]] = ..., tags: Optional[Mapping[str, str]] = ..., sort_keys: bool = ...) -> None
floatwidth.py:2: note: def dump(data: Any, stream: None = ..., Dumper: Any = ..., *, default_style: Optional[str] = ..., default_flow_style: Optional[bool] = ..., canonical: Optional[bool] = ..., indent: Optional[int] = ..., width: Optional[int] = ..., allow_unicode: Optional[bool] = ..., line_break: Optional[str] = ..., encoding: Optional[str] = ..., explicit_start: Optional[bool] = ..., explicit_end: Optional[bool] = ..., version: Optional[Tuple[int, int]] = ..., tags: Optional[Mapping[str, str]] = ..., sort_keys: bool = ...) -> Any
Found 1 error in 1 file (checked 1 source file)
Poking through the `PyYAML` source, it looks the `width` parameter
could probably be anything "comparable", as it's only compared via
the `<` operator[1].
For the LibYAML implementation, however, we have to use `int`s:
>>> stream = StringIO()
>>> dumper = yaml.CDumper(stream, width=float("inf"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/yaml/cyaml.py", line 81, in __init__
version=version, tags=tags)
File "ext/_yaml.pyx", line 973, in _yaml.CEmitter.__init__ (ext/_yaml.c:14797)
OverflowError: cannot convert float infinity to integer
2022-11-08 21:23:47 +00:00
..
2022-11-08 18:13:59 +00:00
2022-11-06 19:45:25 +00:00
2022-06-25 08:09:25 +01:00
2022-07-04 10:29:47 +02:00
2022-11-08 18:28:42 +00:00
2022-11-06 14:02:24 -08:00
2022-11-08 18:28:42 +00:00
2022-10-15 18:54:21 +01:00
2022-11-08 18:28:42 +00:00
2022-11-08 18:28:42 +00:00
2022-06-26 08:56:18 +01:00
2022-10-31 07:04:31 -07:00
2022-06-09 15:49:23 +02:00
2022-11-08 18:28:42 +00:00
2022-08-10 18:56:14 +01:00
2022-10-12 09:35:12 +01:00
2022-07-19 08:11:29 +01:00
2022-10-25 17:57:01 -07:00
2021-10-11 13:41:19 -07:00
2022-10-20 09:32:04 +01:00
2022-06-26 08:56:18 +01:00
2022-07-31 19:19:18 +01:00
2022-11-08 18:13:59 +00:00
2022-09-12 18:32:47 +01:00
2022-11-03 19:53:54 -07:00
2022-08-02 23:08:18 +01:00
2022-10-14 11:02:38 -07:00
2022-06-26 10:30:22 +01:00
2022-08-05 12:12:37 +01:00
2022-06-25 08:16:59 +01:00
2022-10-15 18:54:21 +01:00
2022-10-20 07:15:09 -07:00
2022-11-01 00:26:33 +00:00
2022-10-15 15:16:41 +01:00
2022-06-25 08:16:59 +01:00
2022-10-15 16:00:44 +01:00
2022-10-27 01:29:19 +01:00
2022-10-15 18:54:21 +01:00
2022-10-15 18:54:21 +01:00
2022-06-14 08:48:41 -07:00
2022-06-07 17:33:10 -07:00
2022-06-13 12:24:49 +02:00
2022-10-25 01:34:52 +01:00
2022-07-12 15:32:48 +02:00
2022-10-12 01:30:56 +01:00
2022-10-14 21:08:07 +03:00
2022-09-24 18:32:10 +01:00
2022-11-08 18:28:42 +00:00
2022-11-03 07:38:51 -07:00
2022-11-08 18:28:42 +00:00
2022-11-08 18:28:42 +00:00
2022-11-08 18:28:42 +00:00
2022-11-08 18:28:42 +00:00
2022-06-26 11:36:28 +01:00
2022-11-08 18:13:59 +00:00
2022-11-08 18:28:42 +00:00
2022-11-03 15:32:10 +00:00
2022-11-08 18:28:42 +00:00
2022-10-06 14:20:05 -07:00
2022-10-20 07:11:11 -07:00
2022-08-17 21:53:40 +01:00
2022-07-26 06:26:35 -07:00
2022-06-18 16:27:10 +02:00
2022-11-08 18:28:42 +00:00
2022-07-04 10:29:47 +02:00
2022-10-13 20:54:50 -07:00
2022-09-10 23:10:14 +01:00
2022-10-19 17:58:51 -07:00
2022-11-08 18:28:42 +00:00
2022-11-01 12:37:21 +01:00
2022-11-08 18:28:42 +00:00
2022-10-15 18:54:21 +01:00
2022-11-08 18:28:42 +00:00
2022-06-26 08:56:18 +01:00
2022-04-27 12:42:23 +03:00
2022-10-28 17:30:44 -07:00
2022-11-08 18:28:42 +00:00
2022-10-19 18:00:15 -07:00
2022-11-08 18:28:42 +00:00
2022-06-19 00:43:24 -07:00
2022-10-03 15:11:42 -07:00
2022-07-18 19:02:28 +01:00
2022-06-25 08:15:44 +01:00
2022-08-05 08:55:36 +02:00
2022-10-15 18:54:21 +01:00
2022-11-06 14:50:38 -08:00
2022-10-16 12:47:47 +01:00
2022-09-12 13:30:57 +02:00
2022-11-04 22:56:40 -07:00
2021-10-12 12:30:45 +02:00
2022-10-03 09:33:15 -07:00
2022-07-04 10:29:47 +02:00
2022-10-15 18:54:21 +01:00
2022-10-20 09:37:42 +01:00
2022-11-08 18:13:59 +00:00
2022-10-16 12:47:47 +01:00
2022-07-14 19:27:27 -07:00
2022-07-04 10:29:47 +02:00
2022-06-29 09:54:42 -07:00
2022-10-31 21:08:41 -07:00
2022-10-20 07:10:34 -07:00
2022-11-08 18:28:42 +00:00
2022-11-08 21:23:47 +00:00
2022-11-08 18:13:59 +00:00
2022-11-01 00:27:58 +00:00
2022-11-08 18:28:42 +00:00
2022-07-19 19:15:20 -07:00
2022-11-03 13:41:37 -07:00
2022-10-24 12:58:31 -07:00
2022-11-08 17:30:05 +00:00
2022-05-07 10:35:50 +02:00
2022-11-03 15:32:10 +00:00
2022-06-26 08:56:18 +01:00
2022-11-08 18:28:42 +00:00
2022-07-19 19:15:20 -07:00
2022-11-08 18:28:42 +00:00
2022-10-07 06:03:18 -07:00
2022-09-16 13:54:06 +01:00
2022-07-12 15:32:48 +02:00
2022-06-25 08:15:44 +01:00
2022-11-08 18:13:59 +00:00
2022-10-24 09:48:54 -07:00
2022-09-16 01:36:21 +01:00
2022-11-08 18:28:42 +00:00
2022-11-07 18:34:23 +00:00
2022-10-23 14:30:57 +02:00
2022-09-15 20:06:05 -06:00
2022-11-08 18:28:42 +00:00
2022-11-08 18:28:42 +00:00
2022-10-16 12:47:47 +01:00
2022-07-12 15:32:48 +02:00
2022-10-28 21:46:46 +02:00
2022-10-20 01:41:19 +01:00
2022-11-04 09:16:59 +00:00