-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from akx/bytestrings
Don't require f-strings when the formatee is a bytestring
- Loading branch information
Showing
5 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import re as _re | ||
import token as _token | ||
from tokenize import TokenInfo as _TokenInfo | ||
|
||
PREFIX_RE = _re.compile(r"^[^'\"]*") | ||
|
||
|
||
def is_text_string_token(token: _TokenInfo) -> bool: | ||
if not token.type == _token.STRING: | ||
return False # Not a string at all? Ignore. | ||
# Get the prefix of the string (anything before the first quote) | ||
prefix = PREFIX_RE.match(token.string).group(0).lower() | ||
if 'b' in prefix: | ||
return False # Smells like a bytestring. Ignore it. | ||
return True |
This file contains 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
This file contains 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