Commit Graph

41 Commits

Author SHA1 Message Date
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
Mike
7ce3894f23 [blib2to3] Fixed a typo and removed an unused import. (#848) 2019-05-26 12:10:14 +02: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
ee7151e50f
Mention atomic cache creation in the change log 2019-03-14 17:17:50 +01:00
Anders-Petter Ljungquist
227c2d77b4 Changes default logger used by blib2to3 Driver (#732)
... to stop it from spamming the log when black is used as a library in another
    python application.

When used indirectly by black the logger initiated in `driver.py` will emit
thousands of debug messages making the debug level of the root logger virtually
useless. By getting a named logger instead the verbosity of logging from this
module can easily be controlled by setting its log level.

Fixes #715
2019-03-14 13:39:42 +01:00
Samuel Cormier-Iijima
66aa676278 Fix indent calculation with tabs when computing prefixes (#595)
Closes #262
2019-02-04 18:55:01 -08:00
Anthony Sottile
4d3107233f Atomically write cache files (#674) 2019-01-18 20:59:17 -08:00
Zsolt Dollenstein
883689366c Support parsing of async generators in non-async functions (#165)
This is a new syntax added in python3.7, so black can't verify that reformatting will not change the ast unless black itself is run with 3.7. We'll need to change the error message black gives in this case. @ambv any ideas?

Fixes #125.
2018-08-20 14:47:58 +01:00
Łukasz Langa
048efa7476 Trivial nits 2018-06-19 23:08:10 -07:00
Łukasz Langa
e1ef57a29e Move INDENT value to the postponed prefix
This makes blib2to3's tree output valid again (which was broken by the previous
fiddling with INDENT and DEDENT nodes).

Fixes #334
2018-06-19 20:44:47 -07:00
Łukasz Langa
2cc42f7892 Don't mark subtrees as changed that were already marked. 2018-06-09 19:49:20 -07:00
Łukasz Langa
2228890d62 Cache child sibling lookups
Removes catastrophically quadratic behavior on nodes with very many siblings.
2018-06-09 18:52:46 -07:00
Hugo
9e9ee449b4 Link to GitHub + HTTPS + typos (#303)
* Link to GitHub, update 3.6 minor version

* http -> https

* Fix typos

* The Black style for Black, the project, is italics
2018-06-06 09:50:08 -07:00
Łukasz Langa
c891c65b6b Store grammar pickle caches in CACHE_DIR
Fixes #192

Fixes #203
2018-05-19 14:06:27 -07:00
Christian Heimes
642f240253 Remove grammar pickles from git (#225)
There is no need to keep the pickled grammar files in git. PR #203 will
move them into a user-specific cache directory any way.

See: https://github.com/ambv/black/issues/192
Signed-off-by: Christian Heimes <christian@python.org>
2018-05-18 16:59:05 -04:00
Christian Heimes
adf4ebd2d9 Remove unnecessary shebang lines (#189)
Since black.py is not marked as executable, the shebang in black.py serves
no purpose. black should be invoked through its entry point any way.

token.py is an internal module without a __name__ == '__main__' block or
other executable code. It contains just list of constants and small
helper functions.

Signed-off-by: Christian Heimes <christian@python.org>
2018-05-04 13:52:17 -07:00
Łukasz Langa
54d707e10a Allow standalone comments to close code blocks
Fixes #16
Fixes #32
2018-04-23 16:17:12 -07:00
Łukasz Langa
c86fb36232 Accelerate Unicode identifier support (backport from Lib/tokenize.py) 2018-04-23 14:31:35 -07:00
Łukasz Langa
82198030ee Remove nonsensical grammar from blib2to3 2018-04-23 14:24:14 -07:00
Gregory P. Smith
959ff798bc Put the PSF license in blib2to3/ to mark that code. (#162)
The blib2to3/ code is PSF licensed as that is where the code originated.
This change just drops a proper copy of that license file into the
directory tree to make that clear.
2018-04-23 14:19:24 -07:00
Łukasz Langa
6a9d09cd44 Store pickles for 3.8.0a0 2018-04-18 22:17:00 -07:00
Łukasz Langa
dcd77136f8 Update 3.6.4 grammar pickle 2018-04-18 17:41:49 -07:00
Zsolt Dollenstein
5192ed484b Parse complex expressions in parameters after * and ** 2018-04-17 20:34:02 +01:00
Łukasz Langa
e41844feb7 Remove debug print 2018-04-11 23:22:22 -07:00
Łukasz Langa
9138a75b75 Fix parsing of unaligned standalone comments
Fixes #99
Fixes #112
2018-04-11 23:22:22 -07:00
Zsolt Dollenstein
ecdbf085a7 Add support for all valid string literals (#115) 2018-04-09 14:36:40 -07:00
Łukasz Langa
e36b8c71bb [blib2to3] Support non-ASCII identifiers
This support isn't *exactly* right per PEP 3131 as the regex engine is a bit
too limited for that and I didn't want to spend time on Other_ID_Start and
Other_ID_Continue unless they're actually needed.

Hopefully this doesn't slow it down too much.
2018-04-05 02:29:01 -07:00
Łukasz Langa
63da5d088c 3.6.5 grammar pickles 2018-04-04 09:55:56 -07:00
Łukasz Langa
2d80366ac1 [blib2to3] Make the grammar pickles faster 2018-04-02 18:28:24 -07:00
Łukasz Langa
fc869039eb Don't crash and burn on empty lines with trailing whitespace
Fixes #80
2018-03-26 18:41:25 -07:00
Łukasz Langa
8c565d8684 blib2to3: Never put prefixes on INDENT leaves either 2018-03-23 17:15:47 -07:00
Łukasz Langa
6316e293ac Automatic detection of deprecated Python 2 forms of print and exec
Note: if those are handled, you can't use --safe because this check is using
Python 3.6+ builtin AST.

Fixes #49
2018-03-22 23:19:23 -07:00
Łukasz Langa
5fa38d4c3b Fix tests on 3.7 2018-03-20 19:04:49 -07:00
Łukasz Langa
d9c6b99073 Restore ability to format code with legacy usage of async as a name
Fixes #20
Fixes #42
2018-03-20 18:54:01 -07:00
Łukasz Langa
c90cf42d7c blib2to3: Never put prefixes on DEDENT leaves 2018-03-16 21:47:52 -07:00
Łukasz Langa
907dc6c35e Clean up typing ignores, fix build 2018-03-15 23:26:56 -07:00
Łukasz Langa
ed48bd378d Mention *args and **kwargs backport 2018-03-15 10:58:15 -07:00
Łukasz Langa
f5cc3e3556 Actually use the bundled Grammar.txt 2018-03-14 14:20:16 -07:00
Łukasz Langa
e74117f172 Initial commit 2018-03-14 12:55:32 -07:00