Skip to content
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

Comparison chaining #439

Merged
merged 9 commits into from
Sep 15, 2014
Merged

Comparison chaining #439

merged 9 commits into from
Sep 15, 2014

Conversation

spkersten
Copy link
Contributor

This fixes #309

I've added a new AST node, ComparisonExpr, for (chained) comparison expressions. This node is type checked as were it a boolean-and expression of pair-wise comparisons of all consecutive operands.

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 9, 2014

Thanks for the fix! I don't have time to review it right now, but I will do it later this week (I have time dedicated to mypy on Sunday).

Can you have a look at the Travis CI failure (see Details above). Here is an extract -- it might be a mypy parser issue:

In module imported in mypy/pprinter.py, line 3,
in mypy/test/testdyncheck.py, line 16,
in tests.py, line 17:
mypy/output.py: In member "visit_comparison_expr" of class "OutputVisitor":
mypy/output.py, line 385: Parse error before ,
mypy/output.py, line 385: Parse error before :
mypy/output.py, line 386: Inconsistent indentation
mypy/output.py: At top level:
mypy/output.py, line 525: Inconsistent indentation
mypy/output.py, line 525: Parse error before :
mypy/output.py, line 526: Inconsistent indentation
mypy/output.py, line 614: Inconsistent indentation

@spkersten
Copy link
Contributor Author

It think the errors at line 385 are caused by an existing bug in the mypy parser, which can be reproduced.

mpf.py:

ts = [(1,2), (3,4)]
xs = ['a', 'b']

for (t1, t2), x in zip(ts, xs):
    print(t1, t2, x)

Python runs fine:

$ python3 mpf.py 
1 2 a
3 4 b

But mypy fails to parse it:

$ python3 scripts/mypy mpf.py 
mpf.py, line 5: Parse error before ,
mpf.py, line 5: Parse error before :
mpf.py, line 6: Inconsistent indentation
mpf.py, line 9: Inconsistent indentation

I've created issue #441 for this.

Lines 525 and 614 where not touched by me at all.

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 10, 2014

Yeah, the mypy parser is to blame. For the time being, could you refactor it to use code that is supported by mypy, since otherwise mypy can't type check itself. For example, consider this:

for (t1, t2), x in zip(ts, xs):
    print(t1, t2, x)

It can be written like this (though uglier):

for t, x in zip(ts, xs):
    t1, t2 = t
    print(t1, t2, x)

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 15, 2014

Thanks for the fix -- looks great!

JukkaL added a commit that referenced this pull request Sep 15, 2014
@JukkaL JukkaL merged commit e213759 into python:master Sep 15, 2014
@spkersten spkersten deleted the parsecomp branch September 15, 2014 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comparison chaining bug
2 participants