Skip to content

Allow initial comma #1867

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

Closed
rpuntaie opened this issue Mar 11, 2021 · 2 comments
Closed

Allow initial comma #1867

rpuntaie opened this issue Mar 11, 2021 · 2 comments

Comments

@rpuntaie
Copy link

Allow initial comma.

Final comma works:

t = (
     1,
     2,
    )
x = [
     1,
     2,
    ]
y = {
     1,
     2,
    }
z = {
     1:11,
     2:22,
    }
def fun(
      a,
      b,
     ):
      pass

Initial comma does not work:

t = (
     , 1
     , 2
    )
x = [
     , 1
     , 2
    ]
y = {
     , 1
     , 2
     }
z = {
     , 1:11
     , 2:22
     }
def fun(
     , a
     , b
     ):
      pass

To make the syntax symmetric in this regard
gives more freedom to format the code.

I occasionally found the restriction an unnecessary nuisance.

Before writing a PEP,
I would like to discuss,

  • whether something like that has been proposed already?
  • what counter-arguments there could be?
@pxeger
Copy link
Contributor

pxeger commented Mar 11, 2021

This is not the appropriate place to propose language changes. Try the python-ideas mailing list. However, I don't think you'll get anyone to agree.

What kind of code style are you using where you want to put commas at the start of the line? That is totally non-standard (see PEP 8), ugly, and confusing.

Arbitrary symmetry is not a good reason for changing the language. We don't have a tnirp function just for the sake of symmetry with print because it would be pointless and add extra complication

@encukou encukou closed this as completed Mar 11, 2021
@rpuntaie
Copy link
Author

I surely agree, that not ignoring the sequence is essential. Else one would loose identifier space and thus information. I would never have the idea to make all permutations of p.r.i.n.t point to the same function. Therefore you just made a bad example.

But the comma is just a separator. Why did they allow to have the comma before a closing bracket/parenthesis/brace? Because of symmetry between lines, is my guess.

Occasionally one sees many spaces just the have the final comma aligned vertically. That could be avoided by placing the comma at the beginning.

I personally also have a macro in the editor that evaluates a line in the parameter list, but drops an initial comma before doing that. Therefore this is my preferred formatting.

I don't think that PEP is wrong. I just don't want to be restricted by unnecessary rules. Rules need to have a reason beyond someone dictating them. If that is the case, I follow them, because I see the reason, but not because someone dictates them.

I'll go to Python Ideas, then. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants