From aa580715f77ecebd2f725fb98015f5e467159c81 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Wed, 5 Jul 2023 10:53:14 +0800 Subject: [PATCH 01/10] Fix broken doctest in int<->str len limitation --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 0ac727e0df38b3..ab6492709a8df1 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5548,7 +5548,7 @@ When an operation would exceed the limit, a :exc:`ValueError` is raised: >>> _ = int('2' * 5432) Traceback (most recent call last): ... - ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit. + ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit >>> i = int('2' * 4300) >>> len(str(i)) 4300 @@ -5556,7 +5556,7 @@ When an operation would exceed the limit, a :exc:`ValueError` is raised: >>> len(str(i_squared)) Traceback (most recent call last): ... - ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 8599 digits; use sys.set_int_max_str_digits() to increase the limit. + ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit >>> len(hex(i_squared)) 7144 >>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited. From cf8bd3655112e4013f225b75bba96455014d0332 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 14:19:14 +0800 Subject: [PATCH 02/10] fix `toreadonly` doctest --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ab6492709a8df1..f2e64e945c65a6 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3950,7 +3950,7 @@ copying. >>> m = memoryview(bytearray(b'abc')) >>> mm = m.toreadonly() >>> mm.tolist() - [89, 98, 99] + [97, 98, 99] >>> mm[0] = 42 Traceback (most recent call last): File "", line 1, in From 351b017cd7a88475724a38e14dc1f650d5572943 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 14:48:58 +0800 Subject: [PATCH 03/10] add doctest option for address in `memoryview` --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index f2e64e945c65a6..52e89cc01e2cd1 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3766,7 +3766,7 @@ copying. 98 >>> v[-1] 103 - >>> v[1:4] + >>> v[1:4] # doctest: +SKIP >>> bytes(v[1:4]) b'bce' From 6b6796c5ac1c6fc0b240d81ceb5ac32fda64ba4b Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 15:05:11 +0800 Subject: [PATCH 04/10] fix exception doctest in `cast` --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 52e89cc01e2cd1..0442dee004ac8a 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -4036,8 +4036,8 @@ copying. >>> x = memoryview(b) >>> x[0] = b'a' Traceback (most recent call last): - File "", line 1, in - ValueError: memoryview: invalid value for format "B" + ... + TypeError: memoryview: invalid type for format 'B' >>> y = x.cast('c') >>> y[0] = b'a' >>> b From bc978eb17c117dde5f201c52e06c6f43aa9686a5 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 16:55:20 +0800 Subject: [PATCH 05/10] fix set-like objects doctest --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 0442dee004ac8a..bc9a73abf5a078 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -4789,7 +4789,7 @@ An example of dictionary view usage:: >>> keys ^ {'sausage', 'juice'} {'juice', 'sausage', 'bacon', 'spam'} >>> keys | ['juice', 'juice', 'juice'] - {'juice', 'sausage', 'bacon', 'spam', 'eggs'} + {'bacon', 'spam', 'juice'} >>> # get back a read-only proxy for the original dictionary >>> values.mapping From cf5b0d474b8558ed1818db7e60fefd2f61b71bb3 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 17:06:25 +0800 Subject: [PATCH 06/10] fix dict[str][str] --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index bc9a73abf5a078..7d58d95b591993 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -4996,8 +4996,8 @@ exception to disallow mistakes like ``dict[str][str]``:: >>> dict[str][str] Traceback (most recent call last): - File "", line 1, in - TypeError: There are no type variables left in dict[str] + ... + TypeError: dict[str] is not a generic class However, such expressions are valid when :ref:`type variables ` are used. The index must have as many elements as there are type variable items From b13122e490367ce5edd5b3d5a342deb3f3c4f022 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 17:19:52 +0800 Subject: [PATCH 07/10] fix `int.__subclasses__()` doctest --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 7d58d95b591993..db91a7db39ac22 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5512,7 +5512,7 @@ types, where they are relevant. Some of these are not reported by the definition order. Example:: >>> int.__subclasses__() - [] + [, , , ] .. _int_max_str_digits: From e8c496afbf895be1bc02e6755f398512588753cd Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Mon, 10 Jul 2023 19:59:34 +0800 Subject: [PATCH 08/10] fix union object doctest --- Doc/library/stdtypes.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index db91a7db39ac22..d0d7dd953a96a3 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5206,10 +5206,10 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`. However, union objects containing :ref:`parameterized generics ` cannot be used:: - >>> isinstance(1, int | list[int]) + >>> isinstance([1], int | list[int]) Traceback (most recent call last): - File "", line 1, in - TypeError: isinstance() argument 2 cannot contain a parameterized generic + ... + TypeError: isinstance() argument 2 cannot be a parameterized generic The user-exposed type for the union object can be accessed from :data:`types.UnionType` and used for :func:`isinstance` checks. An object cannot be From a73c1e77fe5eb53d107ca07922e2e34f902d47f5 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Tue, 11 Jul 2023 09:53:46 +0800 Subject: [PATCH 09/10] improve doctest --- Doc/library/stdtypes.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index d0d7dd953a96a3..f3517edb90043d 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3766,7 +3766,7 @@ copying. 98 >>> v[-1] 103 - >>> v[1:4] # doctest: +SKIP + >>> v[1:4] >>> bytes(v[1:4]) b'bce' @@ -4786,10 +4786,10 @@ An example of dictionary view usage:: >>> # set operations >>> keys & {'eggs', 'bacon', 'salad'} {'bacon'} - >>> keys ^ {'sausage', 'juice'} - {'juice', 'sausage', 'bacon', 'spam'} - >>> keys | ['juice', 'juice', 'juice'] - {'bacon', 'spam', 'juice'} + >>> keys ^ {'sausage', 'juice'} == {'juice', 'sausage', 'bacon', 'spam'} + True + >>> keys | ['juice', 'juice', 'juice'] == {'bacon', 'spam', 'juice'} + True >>> # get back a read-only proxy for the original dictionary >>> values.mapping @@ -5203,9 +5203,11 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`. >>> isinstance("", int | str) True - However, union objects containing :ref:`parameterized generics - ` cannot be used:: + However, :ref:`parameterized generics ` in + union objects cannot be checked:: + >>> isinstance(1, int | list[int]) # short-circuit evaluation + True >>> isinstance([1], int | list[int]) Traceback (most recent call last): ... From 6fc53f1f98a7e23ce15e67606e9962b47667999e Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 13 Jul 2023 16:00:00 -0400 Subject: [PATCH 10/10] Add byte length disclaimer --- Doc/library/stdtypes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index f3517edb90043d..092f2719379e8a 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -4006,6 +4006,7 @@ copying. :mod:`struct` syntax. One of the formats must be a byte format ('B', 'b' or 'c'). The byte length of the result must be the same as the original length. + Note that all byte lengths may depend on the operating system. Cast 1D/long to 1D/unsigned bytes::