Skip to content

Conversation

@mr54ndm4n
Copy link

resolve #213

Copy link
Member

@takluyver takluyver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Comments inline.

else:
stk.append(token[idx])
else:
stk.append(token[idx])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments in your parser code? I'm finding it a bit hard to follow.

idx += 1
if len(stk) != 1 or stk[-1] != "EXP":
problems.append("Invalid environment markers syntax")
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this structure - it could easily obscure a bug in the code by catching an overly general exception, and it means all the interesting code is indented a level more than it needs to be.

If you want to jump out of parsing as soon as a problem is detected, I think it's OK to use an early return.

assert len(res) == 1
assert res[0].startswith("Invalid expression")

res = vem("""()))))()extra == "test"(((((((""") # No chained comparisons
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here is misleading, I think

res = vem("""extra == "test" and or (os_name == "nt" or python_version == "2.7")""") # No chained comparisons
assert len(res) == 1
assert res[0] == "Invalid expression \"and or\""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for an empty pair of parentheses, like extra == "test" and ()?

$""", re.IGNORECASE | re.VERBOSE)
MARKER_OP = re.compile(r'(~=|===?|!=|<=?|>=?|\s+in\s+|\s+not in\s+)')


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but as a general rule, please try not to reformat code beyond the bit that you're working on.

VERSION_SPEC = re.compile(r'(~=|===?|!=|<=?|>=?)\s*[A-Z0-9\-_.*+!]+$', re.IGNORECASE)
REQUIREMENT = re.compile(NAME.pattern[:-1] + # Trim '$'
r"""\s*(?P<extras>\[.*\])?
r"""\s*(?P<extras>\[.*\])?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the alignment here back how it was, it's like that deliberately.

@mr54ndm4n
Copy link
Author

mr54ndm4n commented Oct 31, 2018

I'm closing this PR and use new PR instead

@mr54ndm4n mr54ndm4n closed this Oct 31, 2018
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.

Validate parentheses properly in environment markers

2 participants