Commit graph

24 commits

Author SHA1 Message Date
Max R
5fab0d1887 Update hooks and use autopep8 + add-trailing-comma instead of black 2025-07-20 19:13:24 -04:00
anthony sottile
019424b80d add support for t-strings 2025-05-23 16:25:06 -04:00
Stephen Finucane
bdcd5c2c0a Handle escaped braces in f-strings
To use a curly brace in an f-string, you must escape it. For example:

  >>> k = 1
  >>> f'{{{k}'
  '{1'

Saving this as a script and running the 'tokenize' module highlights
something odd around the counting of tokens:

  ❯ python -m tokenize wow.py
  0,0-0,0:            ENCODING       'utf-8'
  1,0-1,1:            NAME           'k'
  1,2-1,3:            OP             '='
  1,4-1,5:            NUMBER         '1'
  1,5-1,6:            NEWLINE        '\n'
  2,0-2,2:            FSTRING_START  "f'"
  2,2-2,3:            FSTRING_MIDDLE '{'     # <-- here...
  2,4-2,5:            OP             '{'     # <-- and here
  2,5-2,6:            NAME           'k'
  2,6-2,7:            OP             '}'
  2,7-2,8:            FSTRING_END    "'"
  2,8-2,9:            NEWLINE        '\n'
  3,0-3,0:            ENDMARKER      ''

The FSTRING_MIDDLE character we have is the escaped/post-parse single
curly brace rather than the raw double curly brace, however, while our
end index of this token accounts for the parsed form, the start index of
the next token does not (put another way, it jumps from 3 -> 4). This
triggers some existing, unrelated code that we need to bypass. Do just
that.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #1948
2024-08-04 15:54:22 -04:00
Anthony Sottile
1ed78d592a handle multiline fstrings in 3.12 2023-07-29 14:33:10 -04:00
Anthony Sottile
43266a2e26 mute FSTRING_MIDDLE tokens 2023-06-12 22:02:26 -04:00
Albert Tugushev
48b2919130 Display list of available formatters with help for --format 2022-10-15 15:39:05 -04:00
Anthony Sottile
e94fb10940 require python>=3.7 2022-08-05 19:51:08 -04:00
Anthony Sottile
f7ef1a6c8b make --ignore order consistent 2022-02-06 08:36:36 -08:00
Anthony Sottile
4e56fc0f6a pregenerate the pycodestyle plugin to avoid call overhead 2022-01-25 13:52:54 -05:00
Anthony Sottile
23a60dd902 use the actual line contents when processing physical lines 2022-01-22 15:27:53 -05:00
Anthony Sottile
d03b9c97cc add a --require-plugins option 2022-01-22 14:08:32 -05:00
Anthony Sottile
c194d6cc30 combine local_plugin_paths and parse_plugin_options 2022-01-18 20:57:09 -05:00
Anthony Sottile
1b58293ad3 refactor plugin loading options to prepare for --require-plugins 2022-01-10 20:06:26 -05:00
Anthony Sottile
b62edd334a fix extended_default_select from plugin loading 2022-01-01 19:26:43 -05:00
Anthony Sottile
a8333e2bf2 move managing of off_by_default / enable_extensions to plugin loading 2022-01-01 18:33:07 -05:00
Anthony Sottile
50d69150c1 rework plugin loading 2021-12-31 15:09:54 -08:00
Anthony Sottile
fa8ac82ee2 add integration test for off_by_default plugin 2021-12-07 12:25:24 -08:00
Anthony Sottile
bbbe0d8048 improve integration tests 2021-11-14 20:39:45 -08:00
Anthony Sottile
af1668bf04 extend black formatting to tests as well 2021-04-18 09:23:48 -07:00
Anthony Sottile
3f10c04fd0 fix mypy errors 2021-04-07 08:28:11 -07:00
Anthony Sottile
358ae85120 automatic: pyupgrade --py36-plus 2021-03-30 17:37:13 -07:00
Anthony Sottile
93a17a806d instrument coverage on tests and require 100% coverage there 2020-03-23 12:15:29 -07:00
Carl Meyer
423980164b Add paths option in local-plugins config file. 2017-10-24 19:58:18 -07:00
Carl Meyer
4e58068657 Add support for local (in-repo, non-setuptools) plugins.
Closes #357
2017-08-03 00:25:37 -07:00