This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: compiler need support in(de)crement operation or all of it should have syntax error.
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, shihai1991, steven.daprano
Priority: normal Keywords:

Created on 2019-06-16 09:46 by shihai1991, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18292 closed shihai1991, 2020-01-31 14:32
PR 18297 closed shihai1991, 2020-01-31 15:48
Messages (8)
msg345738 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2019-06-16 09:46
compiler need support unary operation of in(de)crement or all of it should have syntax error.I have found many user have confused about it(such as:https://stackoverflow.com/questions/2632677/python-integer-incrementing-with). Of course, it is a big change of grammar and it need core developer team to make decision.

If core developer team support it, i will try my best to do it;)

The behavior is:

$ ./python
Python 3.8.0a4+ (heads/master:e225beb, Jun  4 2019, 00:35:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> i = 1;
>>> ++i
1
>>> i++
  File "<stdin>", line 1
    i++
      ^
SyntaxError: invalid syntax
msg345739 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-06-16 10:20
For the reasons already discussed on the Stackoverflow link you gave, Python does not have pre- and post-increment and -decrement operators, and probably never will.

I'm closing this ticket as Won't Fix, but if you wish to discuss it further, you can raise it on Python-Ideas for community feedback. If there is significant interest, you can then write a PEP for it, and if the PEP is approved, then you can re-open this ticket and provide a PR or patch.


https://mail.python.org/mailman3/lists/python-ideas.python.org/

https://www.python.org/dev/peps/
msg345742 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2019-06-16 11:08
Thank for your suggestion,Steven. If python can not support post-increment and -decrement operators now, i think ++i should raise syntax error as i++.
msg345754 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-06-16 13:07
Since ++i already has a meaning, it won't become a syntax error without an extremely good reason, and I don't think this case meets that standard.

But as Steven says, if you want to pursue it, you should start with a discussion on python-ideas.
msg345759 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2019-06-16 15:15
got it, Eric
msg361110 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-01-31 14:42
A discussion was initiated in https://discuss.python.org/t/why-compiler-doesnt-support-in-de-crement-operation-should-we-support-it/2181.

And most of user tend not to support this in(de)crement operation.
msg361113 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-01-31 14:50
Please remember that not all Python programmers come from a C background 
where `++n` is a pre-increment operator. Then may have a OOP background 
where the unary `+` and `-` operators can do anything they like.

Making `--obj` or `++obj` a syntax error is a backwards-incompatible 
change that will break people's code. We take backwards compatibility 
seriously. Python is a mature language with millions of users, we don't 
break their code lightly.

As you were told (twice) last year, this change will not be considered 
until you take it to the Python-Ideas mailing list for feedback. If you 
have done this, please post a link to the discussion.

If you get a consensus that the change is a good idea, you need to find 
a core developer to sponsor a PEP, then write the PEP, and ask the 
Steering Council to approve it. Only then will the PR be approved.
msg361117 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-01-31 15:06
Steven, Thank you for your quick comment.

sure, i will keep this bpo stay in `closed` status until enlist the support of core developers.
History
Date User Action Args
2022-04-11 14:59:16adminsetgithub: 81485
2020-01-31 15:48:24shihai1991setpull_requests: + pull_request17672
2020-01-31 15:06:43shihai1991setmessages: + msg361117
2020-01-31 14:50:15steven.dapranosetmessages: + msg361113
2020-01-31 14:42:08shihai1991setmessages: + msg361110
2020-01-31 14:32:32shihai1991setpull_requests: + pull_request17666
2019-06-16 15:15:35shihai1991setmessages: + msg345759
2019-06-16 13:07:18eric.smithsetnosy: + eric.smith
messages: + msg345754
2019-06-16 11:08:35shihai1991setmessages: + msg345742
2019-06-16 10:20:41steven.dapranosetstatus: open -> closed

versions: + Python 3.9
nosy: + steven.daprano

messages: + msg345739
resolution: wont fix
stage: resolved
2019-06-16 09:46:23shihai1991create