-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Updated .format() to f-strings #30027
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,7 +587,7 @@ def _parse_tfoot_tr(self, table): | |
def _setup_build_doc(self): | ||
raw_text = _read(self.io) | ||
if not raw_text: | ||
raise ValueError("No text parsed from document: {doc}".format(doc=self.io)) | ||
raise ValueError(f"No text parsed from document: {self.io}") | ||
return raw_text | ||
|
||
def _build_doc(self): | ||
|
@@ -616,8 +616,8 @@ def _build_xpath_expr(attrs) -> str: | |
if "class_" in attrs: | ||
attrs["class"] = attrs.pop("class_") | ||
|
||
s = [f"@{k}={repr(v)}" for k, v in attrs.items()] | ||
return "[{expr}]".format(expr=" and ".join(s)) | ||
s = " and ".join([f"@{k}={repr(v)}" for k, v in attrs.items()]) | ||
return f"[{s}]" | ||
|
||
|
||
_re_namespace = {"re": "http://exslt.org/regular-expressions"} | ||
|
@@ -846,7 +846,8 @@ def _parser_dispatch(flavor): | |
|
||
|
||
def _print_as_set(s) -> str: | ||
return "{" + "{arg}".format(arg=", ".join(pprint_thing(el) for el in s)) + "}" | ||
arg = ", ".join(pprint_thing(el) for el in s) | ||
return f"{{{arg}}}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this adding a layer of braces? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might be able to get rid of the pprint_thing, not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The double brace is how to add a literal brace in an f-string, so looks OK |
||
|
||
|
||
def _validate_flavor(flavor): | ||
|
@@ -871,10 +872,8 @@ def _validate_flavor(flavor): | |
|
||
if not flavor_set & valid_flavors: | ||
raise ValueError( | ||
"{invalid} is not a valid set of flavors, valid " | ||
"flavors are {valid}".format( | ||
invalid=_print_as_set(flavor_set), valid=_print_as_set(valid_flavors) | ||
) | ||
f"{_print_as_set(flavor_set)} is not a valid set of flavors, valid " | ||
f"flavors are {_print_as_set(valid_flavors)}" | ||
) | ||
return flavor | ||
|
||
|
@@ -898,11 +897,11 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs): | |
elif hasattr(io, "seekable") and not io.seekable(): | ||
# if we couldn't rewind it, let the user know | ||
raise ValueError( | ||
"The flavor {} failed to parse your input. " | ||
f"The flavor {flav} failed to parse your input. " | ||
"Since you passed a non-rewindable file " | ||
"object, we can't rewind it to try " | ||
"another parser. Try read_html() with a " | ||
"different flavor.".format(flav) | ||
"different flavor." | ||
) | ||
|
||
retained = caught | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you end up making another pass through this file, can you do this in two lines? i.e. keep
s
as it is now and do the join in a separate step