-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Fix for issue 649. #678
Fix for issue 649. #678
Conversation
Looking good! |
@sobolevn I did the rebase. |
@NanduTej please, fix style 🙂 You can run |
@sobolevn I think my parts of the code got through. There are errors in the previous code. |
There are no issues visible to CI in the projects right now: https://travis-ci.org/wemake-services/wemake-python-styleguide/builds But, new rules - reveal new problems! That's why we build new rules 💪 First issue def _check_first_element(
self,
node: ast.AST,
statement: ast.AST,
extra_lines: int,
) -> Optional[bool]:
if statement.lineno == node.lineno and not extra_lines:
return False
return None This code should not raise any violations. It is correct. See the original issue (3rd example): This code from def get_assigned_name(node: ast.AST) -> Optional[str]:
"""
Returns variable names for node that is just assigned.
Returns ``None`` for nodes that are used in a different manner.
"""
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store):
return node.id
if isinstance(node, ast.Attribute) and isinstance(node.ctx, ast.Store):
return node.attr
if isinstance(node, ast.ExceptHandler):
return getattr(node, 'name', None)
return None # this is a meaningful value! Please, make sure that all the examples from the original task work. Second issue
It means that your new method makes the class too complex. Here's how to fix it: Thanks you for your work! I really appreciate it 👍 |
Please enter the commit message for your changes. Lines starting
@sobolevn sorry for spamming so many commits, my flake8 does not give me the full messages as the build was giving me, so I pushed all the changes I could see and tested them. I am still confused as to what the issue is with the 2 'return None'. I have added all the tests mentioned in the issue and all of them are passing. Can you help me out? |
@NanduTej the easiest way to fix it is:
|
If you setup does not match the one from CI, try the clean build: deactivate
rm -rf dist pip-wheel-metadata wemake_python_styleguide.egg-info .venv
poetry install
poetry run make test |
Thanks! This worked. |
@NanduTej how's it going? Do you need any help from my side? 🙂 |
@sobolevn Sorry, didn't finish the work on this. I am out for my convocation ceremony😄. Will get back and work on it in 3 days. |
Had to google what "convocation ceremony" is 😆 Feel free to get back to it when you have the time. |
Hey @sobolevn! I tried to debug but could not get anywhere. Can you help me out further? I did create the ex.py file and pasted the 2 pieces of code and ran the parse.py program. I did not find anything out of order in the output. |
@NanduTej what exactly is your problem? |
On running flake8 ., There is an error popping up. ./wemake_python_styleguide/logic/naming/name_nodes.py 29:5 WPS331 Found local variable that are only used in ./wemake_python_styleguide/visitors/ast/statements.py 219:9 WPS331 Found local variable that are only used in I am unable to debug this. |
returns, return_sub_nodes = self._get_return_node_variables(nodes) | ||
assign = get_assign_node_variables(nodes) | ||
names = get_name_nodes_variable(nodes) | ||
returns, return_sub_nodes = get_return_node_variables(nodes) |
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.
You can insert breakpoint()
(if you are using 3.7, otherwise see https://realpython.com/python-debugging-pdb/) and debug this function.
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.
You can also use ipbd
:
pip install ipdb
export PYTHONBREAKPOINT=ipdb.set_trace
- Set
breakpoint()
where you need it - Run
flake8
on file that raises an unwanted violation
Hey @sobolevn! Can you explain this to me?
|
@NanduTej this is a integration test for several things:
|
Hey @sobolevn! I am sorry I am taking so much time with this. Can you help me with understanding the flow of how flake8 works. Maybe that will give me a clue as to where to look for the error. |
@NanduTej can you please show me the piece of code that does not work for you? Maybe I can help you from there. Since, I am pretty sure that (In case you still need this information, it is right in our docs: https://wemake-python-stylegui.de/en/latest/pages/api/index.html#overview and here's how all classes work: https://wemake-python-stylegui.de/en/latest/pages/api/index.html#api-reference) |
On running flake 8, I run into this error. ./wemake_python_styleguide/logic/naming/name_nodes.py ./wemake_python_styleguide/visitors/ast/statements.py 219:9 WPS331 Found local variable that are only used in The code is executing fine with all my tests. When I push my code, this error will make build fail which is coming when flake8 command is being run. |
So, then add these cases to your tests: correct_example_N = """
def get_assigned_name(node: ast.AST) -> Optional[str]:
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store):
return node.id
if isinstance(node, ast.Attribute) and isinstance(node.ctx, ast.Store):
return node.attr
if isinstance(node, ast.ExceptHandler):
return getattr(node, 'name', None)
return None
""" And: correct_example_N1 = """
class WrongAttributeVisitor(object):
def _is_super_called(self, node: ast.Call) -> bool:
if isinstance(node.func, ast.Name):
if node.func.id == 'super':
return True
return False
""" And then debug what is going on: I wrote a debugging section of documentation just for this case. P.S. Don't forget to rebase your code. |
return_sub_nodes: Dict[str, ast.Return] = defaultdict() | ||
for sub_node in node: | ||
if isinstance(sub_node, ast.Return): | ||
if isinstance(sub_node.value, ast.Name): |
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.
For the correct_example_N we are not collecting the previous returns where I expected them to be collected in return_sub_nodes and so we are running into issues here. The correct_example_N1 is passing the tests. How should we collect those returns here? Example the returns of type ast.Attribute, and should we be collecting them here?
@sobolevn
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.
Sorry, I have missed your question. Can you try to use ast.walk(subnode)
there? I guess that happens because they are not direct children of the give node, but are lower down the tree.
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.
You can try some other task if you are stuck with one. And pass this one to me.
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.
Sure
I have made things!
Checklist
CHANGELOG.md
Related issues