wemake-services / wemake-python-styleguide

The strictest and most opinionated python linter ever!
https://wemake-python-styleguide.rtfd.io
MIT License
2.51k stars 378 forks source link

Enforce consistency in single element tuple #1164

Open sobolevn opened 4 years ago

sobolevn commented 4 years ago

Rule request

Thesis

One can write:

x = (original, )

And also:

x = (original,)

There are two options: with and without whitespace after , We need to be consistent here. I guess that this can be cured with libcst: #1068 This is a consistency rule.

huangleo12 commented 4 years ago

Hi, I'm a student at Umich. Working with @jdrober for a HW assignment. Can we take this in our backlog after #1245?

sobolevn commented 4 years ago

@huangleo12 you sure can! Thanks a lot for your help! 👍

jdrober9 commented 4 years ago

When we run make test before adding our changes we are getting these kind of errors:

poetry run flake8 . ERROR:darglint:Unexpected type in raises expression: <_ast.BinOp object at 0x10feb50b8> ERROR:darglint:Unexpected type in raises expression: <_ast.Compare object at 0x111ffb7b8> ERROR:darglint:Unexpected type in raises expression: <_ast.Compare object at 0x111ffb668> ERROR:darglint:Unexpected type in raises expression: <_ast.BinOp object at 0x118d9deb8> ERROR:darglint:Unexpected type in raises expression: <_ast.BoolOp object at 0x1145dcd68> ERROR:darglint:Unexpected type in raises expression: <_ast.BoolOp object at 0x10e45cfd0> ERROR:darglint:Unexpected type in raises expression: <_ast.BoolOp object at 0x10e45cb00> ERROR:darglint:Unexpected type in raises expression: <_ast.BinOp object at 0x11ba08c50>

is this normal?

sobolevn commented 4 years ago

Yes, this is an issue with darglint: https://github.com/terrencepreilly/darglint/issues/78

You can temporarily downgrade its version.

jdrober9 commented 4 years ago

I tried reverting back to 1.2.0 for darglint and still am producing these errors. Is there another work around for this?

sobolevn commented 4 years ago

@jdrober9 can you please try 1.2.2?

jdrober9 commented 4 years ago

Question:

we tried to add the functions to the existing class but are not able to bc it would require us to make 8 functions and only 7 are allowed. Creating this new class has caused the following error:

wemake_python_styleguide/visitors/tokenize/syntax.py:86: error: "WrongTupleVisitor" has no attribute "_check_space_before_open_paren"

we can't seem to resolve this error as our class looks very similar to WrongKeywordTokenVisitor and we have made the necessary modifications in file_tokens.py as well.

Does anyone know how to fix this issue.

sobolevn commented 4 years ago

You should probably use libst to fix this issue. See #1068

jdrober9 commented 4 years ago

We noticed in that issue they implemented something similar to what we need to do like:

@final class AttributeCSTVisitor(BaseCSTVisitor): """"""

 def visit_Attribute(self, node: Attribute) -> None:
     """
     Checks whitespace around the dot.

     Raises:
         UnnecessarySpaceAroundDotViolation

     """
     self._check_dot(node.dot)

 def _check_dot(self, node: Dot) -> None:
     has_whitespace = (
         not_empty_whitespace(node.whitespace_before) or
         not_empty_whitespace(node.whitespace_after)
     )

     if has_whitespace:
         self.add_violation(UnnecessarySpaceAroundDotViolation(
             self.get_metadata(PositionProvider, node)))

For commas instead of dots. It seems this hasn't been included in the code (cst), has the libst been used before where we could see a working example? Or should we try and recreate this in the code from scratch.

jdrober9 commented 4 years ago

Is there anyway to pull from #1068 so we can incorporate our changes in with theirs? Or would we have to wait until the newest version is released with their changes?

sobolevn commented 4 years ago

No, currently I cannot merge this PR. I am working on a different feature.

But, you can send a PR to that repo / branch. And when it will be the time to merge, I will merge both of them together.