wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Enforce consistency in single element tuple

Open sobolevn opened this issue 5 years ago • 11 comments

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.

sobolevn avatar Feb 18 '20 18:02 sobolevn

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

huangleo12 avatar Mar 29 '20 17:03 huangleo12

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

sobolevn avatar Mar 29 '20 18:03 sobolevn

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?

jdrober9 avatar Apr 06 '20 21:04 jdrober9

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

You can temporarily downgrade its version.

sobolevn avatar Apr 06 '20 22:04 sobolevn

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

jdrober9 avatar Apr 08 '20 15:04 jdrober9

@jdrober9 can you please try 1.2.2?

sobolevn avatar Apr 08 '20 19:04 sobolevn

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.

jdrober9 avatar Apr 14 '20 17:04 jdrober9

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

sobolevn avatar Apr 14 '20 19:04 sobolevn

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 avatar Apr 15 '20 17:04 jdrober9

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?

jdrober9 avatar Apr 18 '20 18:04 jdrober9

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.

sobolevn avatar Apr 18 '20 18:04 sobolevn