Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
* Make most of blib2to3 directly typed and mypyc-compatible
This used a combination of retype and pytype's merge-pyi to do the
initial merges of the stubs, which then required manual tweaking to
make actually typecheck and work with mypyc.
Co-authored-by: Sanjit Kalapatapu <sanjitkal@gmail.com> Co-authored-by: Michael J. Sullivan <sully@msully.net>
* Make black able to compile and run with mypyc
The changes made fall into a couple categories:
* Fixing actual type mistakes that slip through the cracks
* Working around a couple mypy bugs (the most annoying of which being
that we need to add type annotations in a number of places where
variables are initialized to None)
Co-authored-by: Sanjit Kalapatapu <sanjitkal@gmail.com> Co-authored-by: Michael J. Sullivan <sully@msully.net>
Lawrence Chan [Mon, 28 Oct 2019 19:51:45 +0000 (14:51 -0500)]
Fix fmt on/off when multiple exist in leaf prefix (#1086)
The old behavior would detect the existence of a `# fmt: on` in a leaf
node's comment prefix and immediately mark the node as formatting-on,
even if a subsequent `# fmt: off` in the same comment prefix would turn
it back off. This change modifies that logic to track the state through
the entire prefix and take the final state.
Note that this does not fully solve on/off behavior, since any _comment_
lines between the off/on are still formatted. We may need to add
virtual leaf nodes to truly solve that. I will leave that for a separate
commit/PR.
Michael McClimon [Thu, 24 Oct 2019 04:15:12 +0000 (00:15 -0400)]
setup.py: rename _version.py to _black_version.py (#1089)
In #1082, _version.py was renamed to _black_version.py, but the
py_modules line in setup.py wasn't changed, which meant that when
installed from source, running it failed with something like:
```
Traceback (most recent call last):
File "~/.pyenv/versions/3.6.5/bin/black", line 5, in <module>
from black import patched_main
File "~/.pyenv/versions/3.6.5/lib/python3.6/site-packages/black.py", line 55, in <module>
from _black_version import version as __version__
ModuleNotFoundError: No module named '_black_version'
```
Łukasz Langa [Mon, 21 Oct 2019 13:03:01 +0000 (15:03 +0200)]
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.
Matt VanEseltine [Mon, 21 Oct 2019 09:20:13 +0000 (05:20 -0400)]
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.
Jelle Zijlstra [Sun, 20 Oct 2019 16:02:17 +0000 (09:02 -0700)]
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.
Josh Bode [Sun, 20 Oct 2019 14:24:50 +0000 (16:24 +0200)]
Change how venv path is modified in vim plugin (#804)
- Check if black venv path is not already in `sys.path`
- Append (not insert) path so that black doesn't incorrectly import backports (e.g. `typing`)
Avoids this error if `typing` is present in venv:
```
Traceback (most recent call last):
File "<string>", line 56, in <module>
File "/home/josh/.virtualenvs/default/lib/python3.7/site-packages/black.py", line 19, in <module>
from typing import (
File "/home/josh/.virtualenvs/default/lib/python3.7/site-packages/typing.py", line 1356, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "/home/josh/.virtualenvs/default/lib/python3.7/site-packages/typing.py", line 1004, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
```
This is in preparation for adding type annotations to blib2to3 in
order to compiling it with mypyc (#1009, which I can rebase on top of
this).
To enforce that it stays blackened, I just cargo-culted the existing
test code used for validating formatting. It feels pretty clunky now,
though, so I can abstract the common logic out into a helper if that
seems better. (But error messages might be less clear then?)
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.
Andrey [Sun, 13 Oct 2019 17:21:15 +0000 (20:21 +0300)]
#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
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.
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.)
mypy 0.730 fixed a bug involving nonexistent attributes accessed on
modules, which caused an error since COLONEQUAL never got added to
token.pyi. Add it.
Pablo Galindo [Wed, 18 Sep 2019 11:54:40 +0000 (12:54 +0100)]
Support PEP 572 in while statements (#1028)
Commit d8fa8df0526de9c0968e0a3568008f58eae45364 added support for
parsing and formatting PEP572, but it missed the posibility to add
PEP572 syntax in while statements.
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).
* 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
Adam Johnson [Sun, 16 Jun 2019 15:39:03 +0000 (16:39 +0100)]
Add W503 to default flake8 ignore list (#894)
W503 and W504 are mutually exclusive, to do with splitting binary operators across lines. Black reformats code according to W504, putting the operator on the start of the newline, therefore W503 needs to be ignored in the suggested Flake8 config to use with Black.
dylanjblack [Sat, 15 Jun 2019 04:49:49 +0000 (14:49 +1000)]
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.