Skip to content
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

Consider emitting a warning for the use of continuation characters (except in strings) #11252

Open
NeilGirdhar opened this issue May 2, 2024 · 3 comments
Labels
rule Implementing or modifying a lint rule

Comments

@NeilGirdhar
Copy link

The continuation character used outside of strings are no longer necessary as of Python 3.9 thanks to the new PEG parser. This means that we can always use parentheses. And parentheses have the advantage of not interfering with comments, and for some people are easier to read.

Also, doing a grep on Python source suggests that many Python programmers are preferring parenthesis continuations—except in strings.

Would it make sense to warn on them?

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label May 3, 2024
@charliermarsh
Copy link
Member

For completeness, can you give an example of the pattern you want to lint against, and the suggested alternative?

@NeilGirdhar
Copy link
Author

NeilGirdhar commented May 3, 2024

Sure, from the CPython source:

        if self.size_read == self.chunksize and \
           self.align and \
           (self.chunksize & 1):
            dummy = self.file.read(1)

I prefer:

        if (self.size_read == self.chunksize and self.align
                and (self.chunksize & 1)):
            dummy = self.file.read(1)

Of course, it's a matter of opinion, but apparently according a core developor:

Guido and other core developers are not fans of using backslash to negate line-ends. Not only do fence pairs (parentheses, brackets, and braces) negate all contained line-ends, but the use of grouping parentheses has been expanded to eliminate most/all needs for line-end backslashes. For instance, 3.10 added the use of grouping parentheses to write with statements over multiple lines without using backslash. AFAIK, this was the last required use of backslash, line-end in normal code.

@charliermarsh
Copy link
Member

Not a 'decision' but as a heads up I'm generally hesitant to add more rules that are made redundant with the formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants