-
Notifications
You must be signed in to change notification settings - Fork 187
Added matrix multiplication operator handling #246
Conversation
def foo(): | ||
a @ b | ||
""") | ||
parser.parse(code, 'file_path') |
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.
See if there's a way you could avoid repetition (creating the parser and giving file_path
as an argument).
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 don't think this merits refactoring. It's the central action in the test.
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.
The fact that 'file_path'
appears in every test is what bothers me, not the repetition of this call.
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.
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.
src/pydocstyle/parser.py
Outdated
@@ -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 |
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.
Remove TODO
.
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.
Done.
src/pydocstyle/parser.py
Outdated
@@ -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__': |
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.
all
is a builtin function name, consider renaming this variable.
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 agree, but not in this issue.
src/pydocstyle/parser.py
Outdated
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): |
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'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.. 😕
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 changed the code to make this clearer, see if you get it now.
Fixes #191.