Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-134082: Modernize docstrings instring.Formatter
#134083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
9ef4e56
use docstring for `string.Formatter`
picnixz9aa1a87
clarify docstring
picnixzb3815b5
fix punctuation
picnixz3a3de36
Update Lib/string/__init__.py
picnixzb2a33a7
GH UI...
picnixzffc59ef
Update Lib/string/__init__.py
picnixzFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
use docstring for
string.Formatter
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit9ef4e5633e3e59b8571cfec0147786f58bdad3a2
There are no files selected for viewing
37 changes: 16 additions & 21 deletionsLib/string/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,34 +288,33 @@ def convert_field(self, value, conversion): | ||
return ascii(value) | ||
raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) | ||
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. | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
If *field_name* is not None, it is looked up and | ||
formatted with *format_spec* and *conversion*. | ||
""" | ||
return _string.formatter_parser(format_string) | ||
def get_field(self, field_name, args, kwargs): | ||
"""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: | ||
if is_attr: | ||
obj = getattr(obj, i) | ||
else: | ||
obj = obj[i] | ||
return obj, first |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.