Commit Graph

10 Commits

Author SHA1 Message Date
Felix Hildén
a9eab85f22
Mention comment non-processing in documentation (#2306)
This commit adds a short section discussing the non-processing of docstrings
besides spacing improvements, mentions comment moving and links to the
AST equivalence discussion. I also added a simple spacing test for good
measure.

Commit history before merge:

* Mention comment non-processing in documentation, add spacing test
* Mention special cases for comment spacing
* Add all special cases, improve wording
2021-06-08 17:57:23 -04:00
Łukasz Langa
788268bc39 Re-implement magic trailing comma handling:
- when a trailing comma is specified in any bracket pair, that signals to Black
  that this bracket pair needs to be always exploded, e.g. presented as "one
  item per line";

- this causes some changes to previously formatted code that erroneously left
  trailing commas embedded into single-line expressions;

- internally, Black needs to be able to identify trailing commas that it put
  itself compared to pre-existing trailing commas. We do this by using/abusing
  lib2to3's `was_checked` attribute.  It's True for internally generated
  trailing commas and False for pre-existing ones (in fact, for all
  pre-existing leaves and nodes).

Fixes #1288
2020-08-21 16:45:30 +02:00
Michael J. Sullivan
4b449e7471 Fix unstable formatting with some # type: ignores (#1113)
`type: ignore` shouldn't block collapsing a line, since it will still
apply fine to the merged line. This prevents an issue where a reformat
causes it to shift lines and then be merged on a subsequent pass.

There is a downside to this, which is that it can cause a `type:
ignore` to apply to more code than was originally intended. There
might be a way to apply this in a more limited situation, but I'm not
sure what it is.

Fixes #1061.
2019-11-25 14:16:00 -08:00
Jelle Zijlstra
a73d25883a
fix CI (#1078) 2019-10-20 08:35:57 -07:00
Augie Fackler
9854d4b375 Tweak collection literals to explode with trailing comma (#826) 2019-10-20 16:08:34 +02:00
Michael J. Sullivan
1336094634 Fix missed cases in the # type: ignore logic (#1059)
In #1040 I had convinced myself that the type ignore logic didn't
need anything like the ignored_ids from the type comment logic, but I
was wrong, and we do.

We hit these cases in practice a bunch.
2019-10-10 18:25:33 -07:00
Michael J. Sullivan
6fe800933d Fix issue with type comments on lines with trailing commas (#1058)
The code introduced in #1027 to detect whether a type comment appeared
after a regular comment in a Line would spuriously misfire when a leaf
was in the comments dict but had an empty list of comments. This can
occur as an artifact of how comments on trailing commas are handled,
it seems.

(This was discovered trying to test black out on mypy.)
2019-10-10 11:50:51 -07:00
Łukasz Langa
ca9ad698ef
Enhance the type comment patch 2019-03-14 16:26:41 +01:00
Łukasz Langa
1610fd6bc5
Add trailing comma for single as imports, too 2018-09-26 08:26:35 -07:00
Łukasz Langa
f71db23824 Move test data to data 2018-06-06 15:48:38 -07:00