From 9ef4e5633e3e59b8571cfec0147786f58bdad3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 12 May 2025 11:02:01 +0200 Subject: [PATCH 1/6] use docstring for `string.Formatter` --- Lib/string/__init__.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Lib/string/__init__.py b/Lib/string/__init__.py index eab5067c9b133e..3511e93c5858c7 100644 --- a/Lib/string/__init__.py +++ b/Lib/string/__init__.py @@ -264,22 +264,18 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth, return ''.join(result), auto_arg_index - def get_value(self, key, args, kwargs): if isinstance(key, int): return args[key] else: return kwargs[key] - def check_unused_args(self, used_args, args, kwargs): pass - def format_field(self, value, format_spec): return format(value, format_spec) - def convert_field(self, value, conversion): # do any conversion on the resulting object if conversion is None: @@ -292,28 +288,28 @@ def convert_field(self, value, conversion): return ascii(value) raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) - - # returns an iterable that contains tuples of the form: - # (literal_text, field_name, format_spec, conversion) - # literal_text can be zero length - # field_name can be None, in which case there's no - # object to format and output - # if field_name is not None, it is looked up, formatted - # with format_spec and conversion and then used def parse(self, format_string): - return _string.formatter_parser(format_string) + """ + Return an iterable that contains tuples of the form + (literal_text, field_name, format_spec, conversion). + *literal_text* can be zero length and *field_name* + can be None, in which case nothing is formatted. + + If *field_name* is not None, it is looked up and + formatted with *format_spec* and *conversion*. + """ + return _string.formatter_parser(format_string) - # given a field_name, find the object it references. - # field_name: the field being looked up, e.g. "0.name" - # or "lookup[3]" - # used_args: a set of which args have been used - # args, kwargs: as passed in to vformat def get_field(self, field_name, args, kwargs): - first, rest = _string.formatter_field_name_split(field_name) + """Find the object referenced by a given field name. + The field name *field_name* can be for instance "0.name" + or "lookup[3]". The *args* and *kwargs* arguments are + passed to get_value(). + """ + first, rest = _string.formatter_field_name_split(field_name) obj = self.get_value(first, args, kwargs) - # loop through the rest of the field_name, doing # getattr or getitem as needed for is_attr, i in rest: @@ -321,5 +317,4 @@ def get_field(self, field_name, args, kwargs): obj = getattr(obj, i) else: obj = obj[i] - return obj, first From 9aa1a8749b4c30cafbdee35b64185b035008e6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 16 May 2025 13:56:20 +0200 Subject: [PATCH 2/6] clarify docstring --- Lib/string/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/string/__init__.py b/Lib/string/__init__.py index 3511e93c5858c7..dff9107276304c 100644 --- a/Lib/string/__init__.py +++ b/Lib/string/__init__.py @@ -293,10 +293,10 @@ def parse(self, format_string): Return an iterable that contains tuples of the form (literal_text, field_name, format_spec, conversion). - *literal_text* can be zero length and *field_name* - can be None, in which case nothing is formatted. - - If *field_name* is not None, it is looked up and + *literal_text* can be zero length; + + *field_name* can be None, in which case there's no object + to format and output; otherwise, it is looked up and formatted with *format_spec* and *conversion*. """ return _string.formatter_parser(format_string) From b3815b5747e73956b82f64fbff47afa5f61ab383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 16 May 2025 13:56:46 +0200 Subject: [PATCH 3/6] fix punctuation --- Lib/string/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/string/__init__.py b/Lib/string/__init__.py index dff9107276304c..81ca49443bc280 100644 --- a/Lib/string/__init__.py +++ b/Lib/string/__init__.py @@ -293,7 +293,7 @@ def parse(self, format_string): Return an iterable that contains tuples of the form (literal_text, field_name, format_spec, conversion). - *literal_text* can be zero length; + *literal_text* can be zero length. *field_name* can be None, in which case there's no object to format and output; otherwise, it is looked up and From 3a3de365a4b73fbea03f26791c8437b7b690595b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 16 May 2025 13:59:09 +0200 Subject: [PATCH 4/6] Update Lib/string/__init__.py --- Lib/string/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/string/__init__.py b/Lib/string/__init__.py index 81ca49443bc280..0f94fdaf55d629 100644 --- a/Lib/string/__init__.py +++ b/Lib/string/__init__.py @@ -294,7 +294,6 @@ def parse(self, format_string): (literal_text, field_name, format_spec, conversion). *literal_text* can be zero length. - *field_name* can be None, in which case there's no object to format and output; otherwise, it is looked up and formatted with *format_spec* and *conversion*. From b2a33a77952f211cebc9ace2a2964e71c6971914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 16 May 2025 13:59:31 +0200 Subject: [PATCH 5/6] GH UI... --- Lib/string/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/string/__init__.py b/Lib/string/__init__.py index 0f94fdaf55d629..66fd3c13f99318 100644 --- a/Lib/string/__init__.py +++ b/Lib/string/__init__.py @@ -294,6 +294,7 @@ def parse(self, format_string): (literal_text, field_name, format_spec, conversion). *literal_text* can be zero length. + *field_name* can be None, in which case there's no object to format and output; otherwise, it is looked up and formatted with *format_spec* and *conversion*. From ffc59ef087b5c99feacef55901de5a7e700f8479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 16 May 2025 20:04:45 +0200 Subject: [PATCH 6/6] Update Lib/string/__init__.py --- Lib/string/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/string/__init__.py b/Lib/string/__init__.py index 66fd3c13f99318..b7782e042b94eb 100644 --- a/Lib/string/__init__.py +++ b/Lib/string/__init__.py @@ -293,7 +293,6 @@ def parse(self, format_string): Return an iterable that contains tuples of the form (literal_text, field_name, format_spec, conversion). - *literal_text* can be zero length. *field_name* can be None, in which case there's no object to format and output; otherwise, it is looked up and pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy