New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't require typed-ast #2053
don't require typed-ast #2053
Conversation
9e81b0b
to
d717998
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good to me and what I’d had planned to do.
Can you please just add a line to CHANGES.md please. I’ll try get some CI added to nudge for this today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O my bad, I missed CI for >=3.8 is broken. Let’s look into that.
I have some serious concerns about the implementation here and the general side effects of such a change. A review with more detail will come eventually. |
If python2 is optional now, does that mean test configuration should be different? ie: don't run python2 tests under normal configuration, run python2 tests under the optional 'python2' configuration? |
3bec1d4
to
de5d07a
Compare
What on earth is this error, it looks like absolute nonsense.
Removing |
|
All passed 🎉 Currently tests are run with |
Wait a second, why is the dependency on typed-ast here in the first place? is it just to parse python 2? if so the dependencies should not be |
I noticed that ast.parse doesn't include type comments by default.
Should the code be updated to include this parameter? if sys.version_info >= (3, 8):
# TODO: support Python 4+ ;)
for minor_version in range(sys.version_info[1], 4, -1):
try:
return ast.parse(
src,
filename,
feature_version=(3, minor_version),
type_comments=True,
)
except SyntaxError:
continue |
@cooperlees Could you review/address this please. |
9a78b18
to
1fa6628
Compare
f3deb4a
to
b3d97b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for the PR! I know the rest of my review is quite negative, but I genuinely appreciate the time and energy you've put into putting this together!
I don't like this change because it provides the wrong feedback to a not an insignificant group of users. If I (as a Python 3 only user) give Black an invalid file, the Python 3.X parse attempts will fail and then Black exits with a "Black attempted to parse python2 code, [...] please install typed_ast" error... which makes no sense to me as a Python 3 only user. Not only is this hiding the true problem: the input file isn't valid Python 3 code, the confused user, might try the advice to install typed_ast
which 1) might not work or be a pain, and 2) doesn't actually the fix the issue.
Personally I'm open to pushing most if not all of the disruption to the users still using Black's Python 2 support. My idea would be that Black would need --target-version py27
(configured automatically via magic or configured manually) to even attempt Python 2 parsing. Although this falls apart when Black is formatting multiple files at once (since someone is bound to have a mix of Python 2 and 3 files... of which our target-version logic can't really describe).
There's not much actionable in these two paragraphs of feedback. It's something to just think about, perhaps someone else (maybe you!) has a better idea!
I mean, maybe? It may increase safety but let's do that in another PR since it might have an effect we haven't foreshadowed. |
Actually thinking about this more, we could make |
@ichard26 Thanks for the review! Could you please address #2053 (comment) |
Probably something to do with type comments but I'm not sure. |
This seems to be the only usage of type comments. But this won't work with python >= 3.8 because we aren't using the type_ignore_classes = (ast3.TypeIgnore, ast27.TypeIgnore)
if sys.version_info >= (3, 8):
type_ignore_classes += (ast.TypeIgnore,) |
39ca217
to
22aa641
Compare
Only remaining issue in my opinion is that all tests use |
I'd love @ambv be the definitive answer here. But I feel we can move the python2 tests to a separate GitHub action with the plan to eventually deprecate and no longer support. If we were already "stable" I would have said we freeze python2 supported at version X. But we're not there. Others thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve this in general. Good work. There's two nits before we merge this.
Ideally, tests should be running twice: with the python2 extra and without it. We can do this in a separate pull request.
Tests with the python2 extra can be a separate environment in tox.ini, just like fuzz tests are. We need to make sure they are ran on CI. |
I assuming it needs different configuration to not run python 2 tests, And a negative test that expects SyntaxError with python2. |
@KotlinIsland @ambv I'm using Black (commit 201b331 - latest from master) with Python 3.9. It still requires typed-ast package and fails with
|
😳 |
Isn't https://docs.python.org/3.9/library/exceptions.html#exception-hierarchy |
#2044