Bad:
int()
float()
str()
bytes()
bool()
complex()
Good:
0
0.0
''
b''
False
0j
flake8-comprehensions does the same, but only for dict, list, and tuple.
There should be one-- and preferably only one --obvious way to do it.
none = type(None)()
none is None # True
:see_no_evil:
Oh, also bytes() (use b'' instead).
@sobolevn I can take this issue?
But can you please tell me what needs to do? Which the file and test need change and how it would be work?
Thank you.
Also, plz, assign this issue to me on the GitHub UI. Thank you =)
Sorry, @sobolevn what the files need change for resolve this issue?
Something about visitors/ast/functions.py I guess.
First - I want to add a test and then add a code.
What the function will be showing an error after wrong-code in wemake_python_styleguide/visitors/ast/functions.py?
Do I need to add tests for this problem here - tests/test_visitors/test_ast/test_functions/test_wrong_function_calls.py?
Here: tests/test_visitors/test_ast/test_functions/test_unnecessary_literals.py
You have to create this file.
@serhii73 how's it going? Do you need any help from my side?
Sorry, Nikita.
I will write to you in a few days.
I am a little busy this week.
Hello @sobolevn How are you?
@pytest.mark.parametrize('expression', [
'a = int()',
'b = float()',
'c = str()',
])
def test_unnecessary_literals(
assert_errors,
parse_ast_tree,
expression,
default_options,
):
"""Testing an error when we give unnecessary literals."""
tree = parse_ast_tree(expression)
First I want create a test and then to write code in wemake_python_styleguide/visitors/ast/functions.py.
It is the top of my future test.
Then I need to add code as:
visitor = SomeClass(default_options, tree=tree)
visitor.run()
This is SomeClass from wemake_python_styleguide/violations/consistency.py ?
What the class from wemake_python_styleguide/violations/consistency.py I need to use in my test?
Do you know?
Thank you very much!
Well, you need at first to create a violation in consistency.py
Then you write a test, where:
SomeClass is your visitor from functions.pyconsistency.pyOk, I need to change 3 files?
wemake_python_styleguide/visitors/ast/functions.py
tests/test_visitors/test_ast/test_functions/test_unnecessary_literals.py
wemake_python_styleguide/violations/consistency.py
Right?
In my test will be
tree = parse_ast_tree(expression)
Then I will create visitor
visitor = CLASS(default_options, tree=tree)
visitor.run()
This CLASS from what the file? From wemake_python_styleguide/visitors/ast/functions.py ? Right?
@final
class UnnecessaryLiteralsViolation(ASTViolation):
"""
"""
error_template = 'Unnecessary literals'
code = 347
It is right class from wemake_python_styleguide/violations/consistency.py?
@final
class UnnecessaryLiterals(base.BaseNodeVisitor):
pass
This is a class from wemake_python_styleguide/visitors/ast/functions.py
What need to put in this class?
Make it work, do tests, and put PR on review. We'll have a look and say if something wrong :+1: It's difficult to spot something in small pieces of code out of context.
Also, merged PRs could be really helpful as an example of violations implementation.
I got it.
Hello @sobolevn How are you?
Can you, plz, un-assign this issue to me on the GitHub UI?
Because I tnink I don't have time this month for open source.
Maybe someone takes this issue and do it.
Sorry about that.
Happy Hacktoberfest!
No problem, @serhii73! Thanks for your help and your time. See you next month 馃檪
will do
Thanks, @PrVrSs!