Debian Codegraph @

docs/faq.md

raw
1 # Frequently Asked Questions
2
3 The most common questions and issues users face are aggregated to this FAQ.
4
5 ```{contents}
6 :local:
7 :backlinks: none
8 :class: this-will-duplicate-information-and-it-is-still-useful-here
9 ```
10
11 ## Why spaces? I prefer tabs
12
13 PEP 8 recommends spaces over tabs, and they are used by most of the Python community.
14 _Black_ provides no options to configure the indentation style, and requests for such
15 options will not be considered.
16
17 However, we recognise that using tabs is an accessibility issue as well. While the
18 option will never be added to _Black_, visually impaired developers may find conversion
19 tools such as `expand/unexpand` (for Linux) useful when contributing to Python projects.
20 A workflow might consist of e.g. setting up appropriate pre-commit and post-merge git
21 hooks, and scripting `unexpand` to run after applying _Black_.
22
23 ## Does Black have an API?
24
25 Not yet. _Black_ is fundamentally a command line tool. Many
26 [integrations](/integrations/index.md) are provided, but a Python interface is not one
27 of them. A simple API is being [planned](https://github.com/psf/black/issues/779)
28 though.
29
30 ## Is Black safe to use?
31
32 Yes. _Black_ is strictly about formatting, nothing else. Black strives to ensure that
33 after formatting the AST is
34 [checked](the_black_code_style/current_style.md#ast-before-and-after-formatting) with
35 limited special cases where the code is allowed to differ. If issues are found, an error
36 is raised and the file is left untouched. Magical comments that influence linters and
37 other tools, such as `# noqa`, may be moved by _Black_. See below for more details.
38
39 ## How stable is Black's style?
40
41 Stable. _Black_ aims to enforce one style and one style only, with some room for
42 pragmatism. See [The Black Code Style](the_black_code_style/index.md) for more details.
43
44 Starting in 2022, the formatting output is stable for the releases made in the same year
45 (other than unintentional bugs). At the beginning of every year, the first release will
46 make changes to the stable style. It is possible to opt in to the latest formatting
47 styles using the `--preview` flag.
48
49 ## Why is my file not formatted?
50
51 Most likely because it is ignored in `.gitignore` or excluded with configuration. See
52 [file collection and discovery](usage_and_configuration/file_collection_and_discovery.md)
53 for details.
54
55 ## Why is my Jupyter Notebook cell not formatted?
56
57 _Black_ is timid about formatting Jupyter Notebooks. Cells containing any of the
58 following will not be formatted:
59
60 - automagics (e.g. `pip install black`)
61 - non-Python cell magics (e.g. `%%writefile`)
62 - multiline magics
63 - code which `IPython`'s `TransformerManager` would transform magics into
64 - invalid syntax
65
66 See
67 [Using _Black_ with Jupyter Notebooks](guides/using_black_with_jupyter_notebooks.md#cells-that-black-will-skip)
68 for details.
69
70 ## Why does Flake8 report warnings?
71
72 Some of Flake8's rules conflict with Black's style. We recommend disabling these rules.
73 See [Using _Black_ with other tools](labels/why-pycodestyle-warnings).
74
75 ## Which Python versions does Black support?
76
77 _Black_ generally supports all Python versions supported by CPython (see
78 [the Python devguide](https://devguide.python.org/versions/) for current information).
79 We promise to support at least all Python versions that have not reached their end of
80 life. This is the case for both running _Black_ and formatting code.
81
82 Support for formatting Python 2 code was removed in version 22.0. While we've made no
83 plans to stop supporting older Python 3 minor versions immediately, their support might
84 also be removed some time in the future without a deprecation period.
85
86 `await`/`async` as soft keywords/identifiers are no longer supported as of 25.9.0.
87
88 Runtime support for 3.6 was removed in version 22.10.0, for 3.7 in version 23.7.0, for
89 3.8 in version 24.10.0, and for 3.9 in version 25.12.0.
90
91 ## Why does my linter or typechecker complain after I format my code?
92
93 Some linters and other tools use magical comments (e.g., `# noqa`, `# type: ignore`) to
94 influence their behavior. While Black does its best to recognize such comments and leave
95 them in the right place, this detection is not and cannot be perfect. Therefore, you'll
96 sometimes have to manually move these comments to the right place after you format your
97 codebase with _Black_.
98
99 ## Can I run Black with PyPy?
100
101 Yes, there is support for PyPy 3.8 and higher.
102
103 ## Why does Black not detect syntax errors in my code?
104
105 _Black_ is an autoformatter, not a Python linter or interpreter. Detecting all syntax
106 errors is not a goal. It can format all code accepted by CPython (if you find an example
107 where that doesn't hold, please report a bug!), but it may also format some code that
108 CPython doesn't accept.
109
110 (labels/mypyc-support)=
111
112 ## What is `compiled: yes/no` all about in the version output?
113
114 While _Black_ is indeed a pure Python project, we use [mypyc] to compile _Black_ into a
115 C Python extension, usually doubling performance. These compiled wheels are available
116 for 64-bit versions of Windows (both AMD and ARM), Linux (via the manylinux standard),
117 and macOS across all supported CPython versions.
118
119 Platforms including musl-based and/or ARM Linux distributions are currently **not**
120 supported. These platforms will fall back to the slower pure Python wheel available on
121 PyPI.
122
123 If you are experiencing exceptionally weird issues or even segfaults, you can try
124 passing `--no-binary black` to your pip install invocation. This flag excludes all
125 wheels (including the pure Python wheel), so this command will use the [sdist].
126
127 [mypyc]: https://mypyc.readthedocs.io/en/latest/
128 [sdist]:
129 https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist
130
131 ## Why are emoji not displaying correctly on Windows?
132
133 When using Windows, the emoji in _Black_'s output may not display correctly. This is not
134 fixable from _Black_'s end.
135
136 Instead, run your chosen command line/shell through [Windows Terminal], which will
137 properly handle rendering the emoji.
138
139 [Windows Terminal]: https://github.com/microsoft/terminal