Commit Graph

300 Commits

Author SHA1 Message Date
Łukasz Langa
c1fe3aa4f8
Simplify some code flow
Put empty lines after control flow changes.
2019-10-28 17:44:30 +01:00
Łukasz Langa
0cf0d68cf2
Explicitly close .gitignore during processing 2019-10-28 17:42:46 +01:00
Łukasz Langa
adce126949
Remove unnecessary casts after pinning Mypy to >= 0.740 2019-10-28 17:39:52 +01:00
Łukasz Langa
95fd5cb648
Use early returns in get_grammars() to save an indentation level 2019-10-28 17:09:25 +01:00
Łukasz Langa
8adf5f0830
Reword comment 2019-10-28 15:31:37 +01:00
Jelle Zijlstra
e027fc9e75 line_length=1 to reduce churn (#1092) 2019-10-28 15:25:42 +01:00
Łukasz Langa
6dca5278a3
Fix regression: unexpected parentheses around non-mathematical powers
This was caused by an overly liberal application of parentheses in #909 that
fixed #646.

Fixes #1041
2019-10-28 14:55:24 +01:00
Łukasz Langa
58fd7885cd
Docstring nit 2019-10-28 13:00:31 +01:00
Jelle Zijlstra
53808e3902 fix crash with long type annotations (#1093) 2019-10-27 11:31:10 +00:00
Tzu-ping Chung
4c4a51cb6b Do not crash when failing to read an entry (#1090) 2019-10-24 14:19:13 -07:00
Łukasz Langa
a701659da2
s/_version.py/_black_version.py/ (#1082)
Some users are installing Black as a dependency in their project. Having
a _version.py in site-packages is asking for a conflict sooner or later.

Ideally we shouldn't require a separate version file at all, that's an
additional import we need to make. But I'll leave that bikeshedding for
a different time.
2019-10-21 15:03:01 +02:00
jgirardet
e9d4e7b67f add gitignore support using pathspec (#878) 2019-10-21 11:44:53 +02:00
Matt VanEseltine
03766f515b Do not load incompatible cache (#875) (#1034)
A black cache created in Python 3.8 throws an unhandled
ValueError in earlier versions. This is because 3.6 does
not recognize the pickle protocol used as default in 3.8.
Accordingly, this commit:

  - Fixes read_cache to return an empty cache instead.

  - Changes the pickle protocol to 4 as the highest protocol
    fully supported by black's supported Python versions.
2019-10-21 11:20:13 +02:00
Jelle Zijlstra
14b28c89c2
Back out #850 (#1079)
Fixes #1042 (and probably #1044 which looks like the same thing).

The issue with the "obviously unnecessary" parentheses that #850 removed is that sometimes they're necessary to help Black fit something in one line. I didn't see an obvious solution that still removes the parens #850 was intended to remove, so let's back out this change for now in the interest of unblocking a release.

This PR also adds a test adapted from the failing example in #1042, so that if we try to reapply the #850 change we don't break the same case again.
2019-10-20 09:02:17 -07:00
Jelle Zijlstra
a73d25883a
fix CI (#1078) 2019-10-20 08:35:57 -07:00
Yurii Karabas
4b5852e44a Set correct return statement for is_type_comment function (#929) 2019-10-20 16:52:07 +02:00
Joe Antonakakis
b73ec93fa7 Add .svn to default exclusion list (#965) 2019-10-20 16:16:26 +02:00
Augie Fackler
9854d4b375 Tweak collection literals to explode with trailing comma (#826) 2019-10-20 16:08:34 +02:00
Michael J. Sullivan
7b11f04d54 Fix type: ignore line breaking when there is a destructuring assignment (#1065)
It turns out we also need to handle invisible *left* parens added at
the *start* of a line. Refactor `contains_unsplittable_type_ignore` to
handle this more cleanly.
2019-10-14 18:15:18 -07:00
Andrey
6aef6c9d45 #455 Fix bug with tricky unicode symbols (#1047)
* add test for special unicode symbol which usual re can not process correctly
add regex lib which supports unicode 12.1.0 standard
replace re usage in project in favor to regex

* #455 fix dependency
2019-10-13 10:21:15 -07: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
Michael J. Sullivan
d9e71a75cc Don't break long lines when type: ignore is present (#1040)
Fixes #997.
2019-10-02 18:57:49 -07:00
vezeli
5938106ac4 Switch from versioneer to setuptools-scm (#1008) 2019-09-18 13:34:20 +01:00
Michael J. Sullivan
0c44220e21 Don't allow type comments to be merged behind regular comments (#1027)
Type comments only apply if they are the first comment on the line,
which means that allowing them to be pushed behind a regular comment
when joining lines is a semantic change (and, indeed, one that black
catches and fails on).
2019-09-17 13:40:03 -07:00
Rishikesh Jha
ae5588cf07 Print a separate message when there are no inputs given (#999)
Fixes #886.
2019-09-04 12:51:32 +01:00
Joe Antonakakis
3dc461a41a Fix unstable formatting involving unwrapping multiple parentheses (#836) (#961)
This change also unwraps all unnecessary parentheses.
2019-08-23 15:51:29 +01:00
Zsolt Dollenstein
025d2ca4ba
use versioneer to manage __version__ (#981) 2019-08-21 15:42:30 +02:00
Joe Antonakakis
c7495b9aa0 Fix unstable format involving backslash + whitespace at beginning of file (#948) 2019-08-04 10:03:19 +01:00
Joe Antonakakis
65ea568e33 Remove unnecessary if-statement in maybe_make_parens_invisible_in_atom (#964) 2019-08-03 16:33:23 -07:00
Zsolt Dollenstein
2848e2e1d6
Support PEP-570 (positional only arguments) (#946)
Code using positional only arguments is considered >= 3.8
2019-07-28 16:17:33 +01:00
Zsolt Dollenstein
d8fa8df052
Add support for walrus operator (#935)
* Parse `:=` properly
* never unwrap parenthesis around `:=`
* When checking for AST-equivalence, use `ast` instead of `typed-ast` when running on python >=3.8
* Assume code that uses `:=` is at least 3.8
2019-07-28 16:03:23 +01:00
Zsolt Dollenstein
77b6ed1b70 Hello github.com/psf! 2019-07-22 21:41:45 +01:00
Yurii Karabas
90d205d1f5 Use nullcontext in case when lock is None. Shutdown pool after code formatting. (#928) 2019-07-16 18:45:56 +01:00
Min ho Kim
f3bb22a828 Fix typo (#916) 2019-07-01 07:42:30 -07:00
Brandt Bucher
b073c9a4e9 Force parentheses between unary op and binary power. (#909) 2019-06-29 09:35:16 -07:00
Zsolt Dollenstein
7d213c6d43
Fix docstring of schedule_formatting
Fixes #914.
2019-06-28 17:31:54 +01:00
Brandt Bucher
9d9f96a7b4 Fix mypy errors. (#911) 2019-06-25 09:44:12 -07:00
Zsolt Dollenstein
8f380911e0
Pin comment to single leaf in invisible parens (#872) 2019-06-15 07:29:09 +01:00
dylanjblack
9394de150e Fix trailing comma for function with one arg (#880) (#891)
Modified maybe_remove_trailing_comma to remove trailing commas for
typedarglists (in addition to arglists), and updated line split logic
to ensure that all lines in a function definition that contain only one
arg have a trailing comma.
2019-06-14 21:49:49 -07:00
Jelle Zijlstra
1c43252aa3 fix some out-of-date docstrings; other cleanup (#865) 2019-05-26 12:09:11 +02:00
Zsolt Dollenstein
519c06a8cc
Don't introduce quotes to f-string sub-expressions on string boundaries (#871) 2019-05-26 11:58:00 +02:00
Michael Flaxman
cbe455ad66 minor performance improvement (~2% speedup in unit tests) (#858) 2019-05-21 20:02:17 -07:00
Katie McLaughlin
b85c345dbc Remove happiness of error message (#852) 2019-05-16 13:02:17 +01:00
Jelle Zijlstra
957ba24bb6
remove obviously unnecessary parentheses (#850)
Fixes #548
2019-05-15 21:11:04 -07:00
Benjamin Woodruff
448885b256
Move tokenizer config onto grammar, rename flag
Based on the feedback in
https://github.com/python/black/pull/845#issuecomment-490622711

- Remove TokenizerConfig, and add a field to Grammar instead.
- Pass the Grammar to the tokenizer.
- Rename `ASYNC_IS_RESERVED_KEYWORD` to `ASYNC_KEYWORDS` and
  `ASYNC_IS_VALID_IDENTIFIER` to `ASYNC_IDENTIFIERS`.
2019-05-09 17:59:29 +02:00
Benjamin Woodruff
f8617f975d
Add support for always tokenizing async/await as keywords
Fixes #593

I looked into this bug with @ambv and @carljm, and we reached the
conclusion was that it's not possible for the tokenizer to determine if
async/await is a keyword inside all possible generators without breaking
the grammar for older versions of Python.

Instead, we introduce a new tokenizer mode for Python 3.7+ that will
cause all async/await instances to get parsed as a reserved keyword,
which should fix async/await inside generators.
2019-05-09 17:59:29 +02:00
Łukasz Langa
2227e6b1cd
Remove spurious prints 2019-05-09 04:49:48 +02:00
Łukasz Langa
6bb90f22ed
Use to handle legacy async/await handling in assert_equivalent 2019-05-08 23:33:39 +02:00
Jason Fried
866be06646 Make --safe work for Python2.7 syntax, by using typed_ast for safe validation (#840) 2019-05-08 07:45:59 -07:00