Commit Graph

636 Commits

Author SHA1 Message Date
cobalt
3d8129001f
Move wrap_long_dict_values_in_parens to the preview style (#4561) 2025-01-27 17:46:13 -08:00
Pedro Mezacasa Muller
459562c71a
Improve function declaration wrapping when it contains generic type definitions (#4553)
---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2025-01-26 00:43:22 -08:00
Jelle Zijlstra
c0b92f3888
Prepare the 2025 stable style (#4558) 2025-01-24 18:00:35 -08:00
GiGaGon
e58baf15b9
Add test for #1187 (#4559)
Closes #1187
2025-01-23 21:20:47 -08:00
cobalt
584d0331c8
fix: Don't remove parenthesis around long dictionary values (#4377) 2025-01-16 22:09:22 -08:00
pre-commit-ci[bot]
40b73f2fb5
[pre-commit.ci] pre-commit autoupdate (#4547)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/pre-commit/mirrors-mypy: v1.13.0 → v1.14.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.13.0...v1.14.1)

* Fix wrapper's return types to be String or Text IO

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Cooper Ry Lees <me@cooperlees.com>
2025-01-07 11:42:27 -08:00
GiGaGon
3b00112ac5
Fix crash on formatting certain with statements (#4538)
Fixes #3678
2024-12-24 12:25:08 -08:00
GiGaGon
0aabac4fe0
Add regression test for #1765 (#4530) 2024-12-23 10:46:25 -08:00
GiGaGon
3fab5ade71
Prevent f-string merge quote changes with nested quotes (#4498) 2024-12-03 20:44:26 -08:00
Owen Christie
e54f86bae4
Two blank lines after an import should be reduced to one (#4489)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-12-03 20:39:35 -08:00
cobalt
96ca1b6be3
fix: Remove parenthesis around sole list items (#4312) 2024-11-27 19:59:29 -08:00
Matej Aleksandrov
c98fc0c128
Update deprecated type aliases (#4486) 2024-10-23 07:00:55 -07:00
Matej Aleksandrov
484a669699
Replace remaining aliases to built-in types (#4485) 2024-10-14 16:37:58 -07:00
Matej Aleksandrov
fff747d61b
Fix formatting cells with magic methods and starting or trailing empty lines (#4484) 2024-10-14 06:55:59 -07:00
Jelle Zijlstra
32ebb93003
Clean up Python 3.8 remnants (#4473) 2024-10-08 19:11:22 -07:00
Jelle Zijlstra
f1a2f92bba
Include --unstable in cache key (#4466)
Fixes #4465
2024-09-27 13:41:29 -07:00
Matej Aleksandrov
8d9d18c033
Fix skipping Jupyter cells with unknown %% magic (#4462) 2024-09-19 19:35:46 -07:00
Shantanu
2a45cecf29
Fix crashes with comments in parentheses (#4453)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-09-15 19:34:02 -07:00
Shantanu
b4d6d8632d
Drop Python 3.8 support (#4452) 2024-09-15 18:21:21 -07:00
Shantanu
ac018c16ca
Require newer aiohttp for blackd (#4451) 2024-09-15 18:05:23 -07:00
Sam Burnett
98a580bbdc
Added Python and grammar versions to a parser error message (#4378)
---------

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Shantanu Jain <hauntsaninja@gmail.com>
2024-09-08 14:24:54 -07:00
Terence Honles
823a7b0ff0
fix: fix PEP 646 support of tuple unpacking (#4440)
This change fixes unpacking a tuple or generic type when *args is a type
variable tuple.
2024-08-26 08:09:59 -07:00
Kanishk Pachauri
14b6e61970
fix: Enhace black efficiently to skip directories listed in .gitignore (#4415) 2024-08-02 09:24:39 -07:00
Tushar Sadhwani
b1c4dd96d7
fix: respect braces better in f-string parsing (#4422) 2024-08-02 09:21:39 -07:00
Jelle Zijlstra
4b4ae43e8b
Fix incorrect linenos on fstring tokens with escaped newlines (#4423)
I don't think this can affect Black itself much (maybe for formatting
ranges), but I ran into this with https://github.com/JelleZijlstra/lib2toast
2024-08-01 11:54:15 -07:00
Tushar Sadhwani
721dff5493
fix: avoid formatting backslash strings inside f-strings (#4401) 2024-07-10 19:52:37 -07:00
Tushar Sadhwani
b677a643c5
tokenizer: skip lines that are just slash and whitespace (#4343) 2024-06-01 13:01:36 -07:00
Yilei Yang
9c1fd463e1
Make sure Black doesn't crash when fmt:off is used before a closing paren (#4363) 2024-05-15 20:32:27 -04:00
Tomasz Kłoczko
0c033f3eb7
Upgrade some old syntax (#4338)
Signed-off-by: Tomasz Kłoczko <kloczek@github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-04-27 07:54:18 -07:00
Jelle Zijlstra
455de7703e
Fix another f-string regression (#4339) 2024-04-27 01:24:20 -07:00
Jelle Zijlstra
e4aaa8a994
Fix incorrect f-string tokenization (#4332) 2024-04-25 16:45:46 -07:00
Jelle Zijlstra
ba88fc372e
Simplify string tokenization regexes (#4331) 2024-04-24 23:11:31 -07:00
Jelle Zijlstra
3f0f8f1956
Support PEP 696 (#4327) 2024-04-23 22:08:37 -07:00
peterkra25
1354be2525
Add support to style function definitions with newlines before function stubs (#4318)
* Add support to style function definitions containing newlines before function stubs

* Relocated implementation for removal of newlines before function stubs with added tests for comments

---------

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2024-04-23 19:19:56 -07:00
Tushar Sadhwani
f4b644b82f
Prevent wrapping of multiline fstrings in parens (#4325) 2024-04-23 14:16:47 -07:00
Tushar Sadhwani
551ede2825
Add PEP 701 support (#3822)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-04-22 08:19:19 -07:00
Shantanu
836acad863
Improve AST safety check (#4290)
Fixes #4288, regressed by #4270
2024-03-22 20:13:53 -06:00
cobalt
13bd0925eb
fix: Stop moving multiline strings to a new line unless inside brackets (#4289)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
2024-03-22 20:11:01 -06:00
Shantanu
c9d2635b55
Remove mocking from tests (#4287)
Fixes #4275
2024-03-20 18:15:42 -07:00
Yilei Yang
bf1195612c
Fix two logging calls in the test helper (#4286)
They were missing formatting interpolation operators.
2024-03-19 22:04:48 -07:00
rdrll
f78b15712a
Fix formatting for if clauses in match-case blocks (#4269)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-03-16 07:38:07 -07:00
Jelle Zijlstra
f000936726
Fix catastrophic performance in lines_with_leading_tabs_expanded() (#4278) 2024-03-15 12:06:12 -07:00
Samson Umezulike
7b5a657285
Fix --line-ranges behavior when ranges are at EOF (#4273)
Fixes #4264
2024-03-15 11:18:47 -07:00
Kai Sforza
1abcffc818
Use regex where we ignore case on windows (#4252)
On windows the path `FoObAR` is the same as `foobar`, so the output
of `black` on a windows machine could output the path to `.gitignore`
with an upper or lower-case drive letter.
2024-03-12 21:22:10 -07:00
Jelle Zijlstra
6af7d11096
Fix AST safety check false negative (#4270)
Fixes #4268

Previously we would allow whitespace changes in all strings, now
only in docstrings.

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2024-03-09 17:42:29 -08:00
cobalt
e4bfedbec2
fix: Don't move comments while splitting delimiters (#4248)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
2024-03-01 07:02:56 -08:00
cobalt
8af439407c
fix: Don't remove comments along with parens (#4218)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
2024-02-12 06:27:50 -08:00
Shantanu
23dfc5b2c3
Fix ignoring input files for symlink reasons (#4222)
This relates to #4015, #4161 and the behaviour of os.getcwd()

Black is a big user of pathlib and as such loves doing `.resolve()`,
since for a long time it was the only good way of getting an absolute
path in pathlib. However, this has two problems:

The first minor problem is performance, e.g. in #3751 I (safely) got rid
of a bunch of `.resolve()` which made Black 40% faster on cached runs.

The second more important problem is that always resolving symlinks
results in unintuitive exclusion behaviour. For instance, a gitignored
symlink should never alter formatting of your actual code. This kind of
thing was reported by users a few times.

In #3846, I improved the exclusion rule logic for symlinks in
`gen_python_files` and everything was good.

But `gen_python_files` isn't enough, there's also `get_sources`, which
handles user specified paths directly (instead of files Black
discovers). So in #4015, I made a very similar change to #3846 for
`get_sources`, and this is where some problems began.

The core issue was the line:
```
root_relative_path = path.absolute().relative_to(root).as_posix()
```
The first issue is that despite root being computed from user inputs, we
call `.resolve()` while computing it (likely unecessarily). Which means
that `path` may not actually be relative to `root`. So I started off
this PR trying to fix that, when I ran into the second issue. Which is
that `os.getcwd()` (as called by `os.path.abspath` or `Path.absolute` or
`Path.cwd`) also often resolves symlinks!
```
>>> import os
>>> os.environ.get("PWD")
'/Users/shantanu/dev/black/symlink/bug'
>>> os.getcwd()
'/Users/shantanu/dev/black/actual/bug'
```
This also meant that the breakage often would not show up when input
relative paths.

This doesn't affect `gen_python_files` / #3846 because things are always
absolute and known to be relative to `root`.

Anyway, it looks like #4161 fixed the crash by just swallowing the error
and ignoring the file. Instead, we should just try to compute the actual
relative path. I think this PR should be quite safe, but we could also
consider reverting some of the previous changes; the associated issues
weren't too popular.

At the same time, I think there's still behaviour that can be improved
and I kind of want to make larger changes, but maybe I'll save that for
if we do something like #3952

Hopefully fixes #4205, fixes #4209, actual fix for #4077
2024-02-12 00:04:09 -08:00
Shantanu
a20100395c
Simplify check for symlinks that resolve outside root (#4221)
This PR does not change any behaviour.

There have been 1-2 issues about symlinks recently. Both over and under
resolving can cause problems. This makes a case where we resolve more
explicit and prevent a resolved path from leaking out via the return.
2024-02-10 23:55:01 -08:00
Logan Hunt
dab37a6a11
Remove redundant parentheses in case statement if guards (#4214)
A follow up to #4024 but for `if` guards in `case` statements. I noticed this
when #4024 was made stable, and noticed I had some code that had extra parens
around the `if` guard.
2024-02-07 06:55:02 -08:00