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

Added matrix multiplication operator handling #246

Merged
merged 3 commits into from Apr 17, 2017

Conversation

Projects
None yet
2 participants
@Nurdok
Copy link
Member

Nurdok commented Apr 16, 2017

Fixes #191.

@Nurdok Nurdok requested a review from shacharoo Apr 16, 2017

def foo():
a @ b
""")
parser.parse(code, 'file_path')

This comment has been minimized.

@shacharoo

shacharoo Apr 16, 2017

Member

See if there's a way you could avoid repetition (creating the parser and giving file_path as an argument).

This comment has been minimized.

@Nurdok

Nurdok Apr 17, 2017

Member

I don't think this merits refactoring. It's the central action in the test.

This comment has been minimized.

@shacharoo

shacharoo Apr 17, 2017

Member

The fact that 'file_path' appears in every test is what bothers me, not the repetition of this call.

This comment has been minimized.

@Nurdok

Nurdok Apr 17, 2017

Member

Allow me to quote myself:

The thing is, while this string appears in many tests, it is an arbitrary string, which is coincidentally the same. We gain nothing from refactoring it out into a constant, while losing readability.

@@ -271,7 +276,7 @@ class Parser(object):
def parse(self, filelike, filename):
"""Parse the given file-like object and return its Module object."""
# TODO: fix log

This comment has been minimized.

@shacharoo

shacharoo Apr 16, 2017

Member

Remove TODO.

This comment has been minimized.

@Nurdok

Nurdok Apr 17, 2017

Member

Done.

@@ -373,9 +380,12 @@ def parse_definitions(self, class_, all=False):
while self.current is not None:
self.log.debug("parsing definition list, current token is %r (%s)",
self.current.kind, self.current.value)
self.log.debug('got_newline: %s', self.stream.got_newline)
if all and self.current.value == '__all__':

This comment has been minimized.

@shacharoo

shacharoo Apr 16, 2017

Member

all is a builtin function name, consider renaming this variable.

This comment has been minimized.

@Nurdok

Nurdok Apr 17, 2017

Member

I agree, but not in this issue.

elif self.current.kind == tk.OP and self.current.value == '@':
elif (self.current.kind == tk.OP and
self.current.value == '@' and
self.stream.got_newline):

This comment has been minimized.

@shacharoo

shacharoo Apr 16, 2017

Member

I'm having trouble understanding why this works. As far as I understand, stream.got_newline only specifies if the previous token was a newline, not if the whole line was just an empty new line. Let's take your test case:

(a
@b)
@foo
def bar():
    ...

If what I said is correct, how does this condition fails to detect @b) as another decorator? I'm guessing that it's something I didn't get about the way the parser works :^)
I couldn't find anywhere a part that builds a parse tree for expressions which will ignore the contents of the parentheses.. 😕

This comment has been minimized.

@Nurdok

Nurdok Apr 17, 2017

Member

I changed the code to make this clearer, see if you get it now.

@Nurdok Nurdok merged commit 9f462f6 into PyCQA:master Apr 17, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@Nurdok Nurdok deleted the Nurdok:feature/matrix-mul branch Apr 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment