flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code. https://flake8.pycqa.org
Find a file
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
.github add 3.12 to ci matrix 2023-07-29 14:30:55 -04:00
bin require python>=3.7 2022-08-05 19:51:08 -04:00
docs Fix wording of plugins documentation 2024-07-23 13:39:49 +02:00
example-plugin require python>=3.7 2022-08-05 19:51:08 -04:00
src/flake8 Handle escaped braces in f-strings 2024-08-04 15:54:22 -04:00
tests Handle escaped braces in f-strings 2024-08-04 15:54:22 -04:00
.bandit.yml Simplify bandit config and allow assert 2019-09-07 23:42:33 -07:00
.gitignore ignore .coverage files in --parallel-mode 2019-05-01 17:08:10 +01:00
.mailmap Update name across the project post-marriage 2017-07-27 18:47:38 -05:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate 2024-01-08 21:35:25 +00:00
.pre-commit-hooks.yaml Turn off pre-commit's automated multiprocessing 2019-01-27 17:26:45 -08:00
.pylintrc fix pylintrc warnings 2023-07-29 14:36:44 -04:00
.readthedocs.yaml add minimal rtd configuration 2023-07-31 19:41:56 -04:00
CONTRIBUTING.rst where possible http->https and fix links 2022-02-10 15:47:58 -05:00
CONTRIBUTORS.txt Tidy up last few bits for performance improvement 2016-12-20 18:29:10 -06:00
dev-requirements.txt drop python3.4 2020-10-02 16:47:00 -07:00
LICENSE Update the copyright in the LICENSE 2016-06-25 10:49:32 -05:00
pytest.ini rework plugin loading 2021-12-31 15:09:54 -08:00
README.rst add myself to maintenance 2023-01-11 09:19:54 -05:00
setup.cfg latest pycodestyle 2024-06-15 17:30:39 -04:00
setup.py require python>=3.7 2022-08-05 19:51:08 -04:00
tox.ini improve coverage 2023-07-29 15:46:40 -04:00

.. image:: https://github.com/PyCQA/flake8/workflows/main/badge.svg
   :target: https://github.com/PyCQA/flake8/actions?query=workflow%3Amain
   :alt: build status

.. image:: https://results.pre-commit.ci/badge/github/PyCQA/flake8/main.svg
   :target: https://results.pre-commit.ci/latest/github/PyCQA/flake8/main
   :alt: pre-commit.ci status

.. image:: https://img.shields.io/discord/825463413634891776.svg
   :target: https://discord.gg/qYxpadCgkx
   :alt: Discord

========
 Flake8
========

Flake8 is a wrapper around these tools:

- PyFlakes
- pycodestyle
- Ned Batchelder's McCabe script

Flake8 runs all the tools by launching the single ``flake8`` command.
It displays the warnings in a per-file, merged output.

It also adds a few features:

- files that contain this line are skipped::

    # flake8: noqa

- lines that contain a ``# noqa`` comment at the end will not issue warnings.
- you can ignore specific errors on a line with ``# noqa: <error>``, e.g.,
  ``# noqa: E234``. Multiple codes can be given, separated by comma. The ``noqa`` token is case insensitive, the colon before the list of codes is required otherwise the part after ``noqa`` is ignored
- Git and Mercurial hooks
- extendable through ``flake8.extension`` and ``flake8.formatting`` entry
  points


Quickstart
==========

See our `quickstart documentation
<https://flake8.pycqa.org/en/latest/index.html#quickstart>`_ for how to install
and get started with Flake8.


Frequently Asked Questions
==========================

Flake8 maintains an `FAQ <https://flake8.pycqa.org/en/latest/faq.html>`_ in its
documentation.


Questions or Feedback
=====================

If you have questions you'd like to ask the developers, or feedback you'd like
to provide, feel free to use the mailing list: code-quality@python.org

We would love to hear from you. Additionally, if you have a feature you'd like
to suggest, the mailing list would be the best place for it.


Links
=====

* `Flake8 Documentation <https://flake8.pycqa.org/en/latest/>`_

* `GitHub Project <https://github.com/pycqa/flake8>`_

* `All (Open and Closed) Issues
  <https://github.com/pycqa/flake8/issues?q=is%3Aissue>`_

* `Code-Quality Archives
  <https://mail.python.org/mailman/listinfo/code-quality>`_

* `Code of Conduct
  <https://flake8.pycqa.org/en/latest/internal/contributing.html#code-of-conduct>`_

* `Getting Started Contributing
  <https://flake8.pycqa.org/en/latest/internal/contributing.html>`_


Maintenance
===========

Flake8 was created by Tarek Ziadé and is currently maintained by `anthony sottile
<https://github.com/sponsors/asottile>`_ and `Ian Cordasco
<https://www.coglib.com/~icordasc/>`_