wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Do not allow `super()` without parameters in generator expressions
This bug: https://bugs.python.org/issue46175
We need to require super(cls, self) in this case.
Hi ! I would like to work on this issue :)
@nasdev-cmd thank you!
Hello, is this issue still open? If so, I would appreciate it greatly if I could provided with the information of where is the code linked to this behavior located.
@kitsiosvas I think that we can add this check here: https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/visitors/ast/classes.py
Are you familiar with python's AST?
@sobolevn I am somewhat familiar with AST indeed. Are there any other similar checks that I could consult? I've been studying the code you included in your previous message to understand what exactly I will need to implement. Thank you.
You can take a look at this: https://github.com/wemake-services/wemake-python-styleguide/blob/61d4fa55c7898bb124ccf573219e8ccaac543742/wemake_python_styleguide/visitors/ast/functions.py#L95-L102
It just checks for wrong functions. But, in this case you will also need the context. See https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/logic/walk.py
If I understand it correctly, I need to somehow check if super() exists as a node with parent a generator expression and it's kids are not in the form you have pointed out initially (super(cls, self)). I don't know if I am missing something. Any input is more than welcome.
Yes, sounds right!
If super call:
- is inside a gen expr
- and does not have two args
We raise a violation.
@sobolevn Thank you for your quick reply. I am having trouble figuring out how do I check if a node is inside a generator expression. Is there a tactic that I am missing? Sorry for making this threat a long one.
Edit: I am thinking of something like using get_closest_parent(node, parents) method. As first argument there will be the super() call node, and as second argument I will have to include generator expressions (not sure on how that is implemented).
If it returns null then super() is not in a gen expr.
I would go this way:
- Find
ast.Callnodes, check name to besuper - Check args count (it is fast and cheap)
- Then
get_closest_parent(call, ast.GeneratorExpr)
In order to get the node's name I would have to use given_function_called(node, to_check: Container[str]) method.
What would I use as Container in this case. I couldn't find anything clear on this. Or maybe there is another way of getting the name of the node?
given_function_called(node, {'super'})
I have implemented the feature. Should I issue a Pull Request for review?
Please! 👍
According to the "Raise a violation" part, I tried doing something similar to https://github.com/wemake-services/wemake-python-styleguide/issues/2310#issuecomment-1023135723 , but it raises errors apparently. I couldn't figure out what is the proper way of achieving this, so far. Will keep searching, but any help is amazing. Thank you.
does this issue still exists , I want to contribute in this project , actually its my first opensource contribution , so any help regarding this really appreciated
Can I take this issue over?
Please! Can you also check other comprehensions? And nested functions?
I'll do what I can.