16

While reviewing this suggested edit, I was unsure on whether to accept or reject.

The original answer's code works for Python 2, however the edit changes the print call to work for Python 3. The library call in question was not changed and still remains correct.

I think that edits which update code for a new version qualify as "Clearly conflicts with author's intent", however the question is 10 years old and Python 2 has since been deprecated. Users who visit this answer will most likely be using Python 3, and even if they weren't the important part of the answer remains intact and backwards-compatible.

So, is this edit acceptable or not? I can see it both as conflicting with the author's intent and just some general housekeeping.

15
  • 5
    At "best" I would suggest that it conflicts with the author's intent. I feel that a "better" edit would be to add a note what the Python 3 equivalent operator would be, without changing the existing code example(s). Considering that the question uses print h (rather than print(h)), then the edit could actually be invalidating the answer.
    – Thom A
    Commented Nov 4, 2022 at 13:50
  • 1
    The changes the the links are pointless too, they already redirect appropriately.
    – Thom A
    Commented Nov 4, 2022 at 13:58
  • 9
    I doubt anyone had a specific intent of never supporting Python 3 back in 2011. The change doesn't even break Python 2 compatibility. Commented Nov 4, 2022 at 14:11
  • 1
    To add context to MisterMiyagi's comment, this question shows the difference and in this case the edit didn't break anything Commented Nov 4, 2022 at 14:14
  • Related: Changing the emphasis of Python answers from Python 2 to Python 3 (one answer and 16 comments) and Are edits that make Python 2 code also compatible with Python 3 discouraged? (without any answers or comments) Commented Nov 4, 2022 at 15:00
  • 1
    As MisterMiyagi observes, print(...) is valid syntax in Python2 and Python3, so the change I don't think is destructive. OTOH the Python3 interpreter emits a very helpful error message if it gets print without parentheses, so the edit is minimally beneficial. Commented Nov 4, 2022 at 15:06
  • 1
    @PeterMortensen I'm sure there was another post about changing Python2 code to Python3, where the consensus was against doing so, but I can't find it. Commented Nov 4, 2022 at 15:07
  • 1
    @snakecharmerb: Me too. Perhaps it was deleted? Commented Nov 4, 2022 at 15:11
  • 1
  • @snakecharmerb: Good find. It looks like the canonical question. Commented Nov 4, 2022 at 15:16
  • 2
    @snakecharmerb Not sure if that other question is applicable. This question here is about a change that works in both versions. That question linked is specifically about changes that cannot work in both versions; many of its answers specifically refer to the loss of Python 2 compatibility being the issue. Commented Nov 4, 2022 at 15:19
  • @MisterMiyagi fair point. Although I think it does provide some context. Commented Nov 4, 2022 at 15:32
  • @snakecharmerb That question is related, but it was also posted in 2017, before Python 2 was deprecated. I feel like the situation is a little different now because Python 2 is actively discouraged.
    – Michael M.
    Commented Nov 4, 2022 at 15:37
  • 2
    @DonaldDuck ironically, I think it doesn't answer OP's question, because of the same question of datedness. Commented Nov 4, 2022 at 22:23
  • A reminder on Zen: Practicality beats purity. Edits should be judged on a practical basis by the value that they bring, not merely on the purity of preserving "intent". (Intent is ambiguous and open to interpretation anyways.) Does the edit noticeably improve the post for the majority future readers? Accept. Commented Nov 4, 2022 at 23:50

4 Answers 4

18

Obviously Yes

I wish to offer the dissenting view, in strong terms.

Edits like this should be strongly encouraged, as they are essential to the proper working of the site. If people are pointing at policy to reject them then there is clearly something very wrong with policy.

I make the following observations:

  1. I have (as a 2k+ user) made many similar edits (unilaterally) myself without running into resistance.

  2. The print in the code shown is entirely incidental to the technique being shown, anyway. If this Q&A pair were posted today, someone would have come along, judged the missing parentheses as a typo, and edited them in without a second thought. Older answers should not get special privileges because of their age. That's not how a library (really, a knowledge base) works.

  3. In the specific case, there is no indication of the version to use. Even at the time the question was posted, 3.2 was out, so it is entirely conceivable that OP was using 3.x. It's true that this would make 2.x-specific answers just as valid as 3.x-specific ones.
    Meanwhile, as MisterMiyagi rightly points out, the edited version still works in a 2.x environment. There was no request in the question for version-specific code, and nothing about the problem that fundamentally changes the approach in a version-specific way. Consequently, it seems absurd to me to suggest that "authorial intent" includes "making the answer specific to 2.x entirely arbitrarily". If it somehow does, I think the site has a compelling interest in overriding that intent.

  4. Python 2.7's EOL was over 2 years ago. It, along with the rest of the 2.x versions, is approximately as outdated as Windows 7. 3.x behaviour should therefore be assumed default. I would go so far as to say that, in the absence of a tag on the question that is justified by the question itself, an answer that requires a 2.x environment to run cannot reasonably be considered "working code". Because 2.x is so far out of date, and because of its ever-dwindling market share, the onus should be on 2.x users to adapt existing 3.x code, or to ask and/or research 2.x-specific questions (and justify their situation when asking). Not the other way around.

  5. A major part of the reason we have edits is so that content can be kept up-to-date. Programmers keep making running jokes about copying and pasting code from Stack Overflow - it's enough of a meme that the blog decided to run with it twice in a row.
    As fun as it is to fantasize about leaving booby traps for people who don't understand the code they're reading, that's also clearly contrary to the intended working of the site. Aside from the utility of copying and pasting code from Stack Overflow to get through one's work day, the site clearly values working code in answers for all the same reasons it values reproducibly-non-working code in questions.
    Those who copy and paste this code are overwhelmingly likely to get a SyntaxError. Yes, they will all probably be better served by deleting the print and doing something else with the h dict instead. I don't think this diminishes the point, however. We want the example in the answer to work as is (for as many readers as possible). Just like we want the example in the question to show the problem, and not show other problems that create a distraction.

1
  • This presents an overwhelming argument in favor of correcting print foo to print(foo) unless there is a specific reason not to. Commented Jan 2 at 21:50
13

TL;DR - This isn't an acceptable edit (even knowing this works for both Python versions)

Let's talk about the moving parts here for a second. See below for a more detailed talk about this specific issue

  1. The question is version agnostic. It uses the generic tag
  2. The answer clearly answers the question. It's accepted and decently upvoted
  3. Python is a bit weird in the 2.X vs 3.X split. There's two ways to do a lot of things.

Edits should not replace working code, even if the methodology is obsolete. The catch here is it removed the 2.X answer for a 3.X answer. New answers come along all the time, but this should either

  1. Be a comment
  2. Be another answer

Both are valid reasons to reject this.


I'm editing this in because there's a different sub-issue here: the edit was valid syntax in both versions. I'll use this from MisterMiyagi's post, since it's concise:

It is important that the change does not invalidate the previous answer scope: a single-argument print is backwards compatible to Python 2.

The early voting that's happening in this Meta seems to be related to that sentiment. Another comment of his:

Yes, I expect some level of subject matter expertise from edit reviewers. Having to judge whether two versions are the technically equivalent is frequently required, not just for code changes. Knowing that print(x) will work in both versions of Python does not seem exceptional to me.

Therein lies the problem: you can't expect that. The Suggested Edit queue is, hands down, the most clogged queue we have. There's a hard limit of 500 edits allowed to sit in there. We need reviewers, and we cannot demand that only subject matter experts (SMEs) review what they already know. That would mean you only review a handful of things. Per the FAQ entry

If changing the syntax errors or typos would result in the code doing something other than what the answer says it will, consider creating a comment or a separate answer explaining your change. If posting another answer with only that change seems like it won't provide added value to future visitors, it probably doesn't change logic or functionality and should be an edit instead.

This isn't a typo, it's simply another way to express the same thing. But adding parenthesis isn't something you just do in most languages. That's control syntax you're dealing with, and just because Python will accept it with or without parenthesis does not mean it should be approved. From the same FAQ entry (emphasis mine)

If you do not have 2,000 reputation allowing you to edit without review, you should be sure to include a good Edit Summary. Reviewers may not be an expert in the language you are submitting an edit for, and may click 'Reject' if they aren't sure if your edit meets these guidelines. Adding a good Edit Summary will help minimize the chance of them making the wrong decision.

What was the edit message here?

fixed links and print statement for python3

As someone with a lot of reviews under my belt, I see this a lot, where some new user makes a suggested edit to "fix" code (and, in cases where I am an SME, I sometimes facepalm at their "fixes"). Reviewers cannot be required to know if the suggested syntax will work and so our position is we err on the side of rejection. This just happens to be one of the rare times where the edit makes no syntactical difference.

"Adding a separate entry for the Python 3 way …" This seems quite frankly excessive to me. We're talking about a single pair of parenthesis. The syntax has no bearing at all on the actual problem of the Q&A, an answer specifically with explanations for Python3 syntax would add nothing but distraction.

A good edit here will either explain the syntax, or be a separate post (example with different syntax for the same thing).

4
  • 3
    I protest to styling this as a rebuttal to my posts. This is arguing about way more than what I actually said. Commented Nov 4, 2022 at 16:07
  • @MisterMiyagi As I mentioned, this may not be the proper format to debate the underlying issue. There's a lot of moving parts there and there's only so much to shoehorn into the Q&A format. It might be worth making a separate Meta post about just that.
    – Machavity Mod
    Commented Nov 4, 2022 at 16:19
  • 7
    From the editor's point of view I can see how not all reviewers knowing Python could be an argument for not suggesting such edits in the first place, but from the reviewer's point of view, I don't see why a reviewer who does know that print(...) works in Python 2 shouldn't approve it. Commented Nov 4, 2022 at 17:31
  • 4
    We think people who don't understand Python should be reviewing edits to Python code? That explains why edits get through that change the meaning by altering the indentation.
    – khelwood
    Commented Nov 6, 2022 at 8:42
8

Yes, in general it is acceptable to make small changes to bring posts up to date:

Help: Why can people edit my posts? How does editing work?

Common reasons for edits include:

  • […]
  • To correct minor mistakes or add updates as the post ages

It is important that the change does not invalidate the previous answer scope: a single-argument print is backwards compatible to Python 2.

7
  • 2
    You're assuming everyone who reviews this knows Python well enough to go "Oh, those are the same thing". This does not appear to be a "minor" change. Adding a separate entry for the Python 3 way would have been better, or having a separate answer (hint hint) explaining what syntax changed.
    – Machavity Mod
    Commented Nov 4, 2022 at 14:46
  • 5
    @Machavity 'This does not appear to be a "minor" change.' It does in my book. I even considered adding that rejecting the change on the grounds of being too minor would be fine as well. Commented Nov 4, 2022 at 14:50
  • 8
    @Machavity Yes, I expect some level of subject matter expertise from edit reviewers. Having to judge whether two versions are the technically equivalent is frequently required, not just for code changes. Knowing that print(x) will work in both versions of Python does not seem exceptional to me. Commented Nov 4, 2022 at 14:53
  • 3
    @Machavity "Adding a separate entry for the Python 3 way …" This seems quite frankly excessive to me. We're talking about a single pair of parenthesis. The syntax has no bearing at all on the actual problem of the Q&A, an answer specifically with explanations for Python3 syntax would add nothing but distraction. Commented Nov 4, 2022 at 14:59
  • 4
    @Machavity You're assuming everyone who reviews this knows Python well enough -- if someone isn't sure about an edit then they are free to skip that review. In case that edit would be rejected, based on not knowing, well the system isn't perfect. But OP's question was if particular edits about print should be acceptable. Commented Nov 4, 2022 at 15:43
  • I edited my post to offer a proper rebuttal. If we're going to continue on this trajectory, we'll need to spin that part off into its own post.
    – Machavity Mod
    Commented Nov 4, 2022 at 15:49
  • 5
    "You're assuming everyone who reviews this knows Python well enough to go "Oh, those are the same thing"." Not at all. If there's an edit that changes code, and an edit reason claiming that the change to the code is a deliberate fix for something, and you lack the domain knowledge to either verify or refute that claim, that's what the Skip button is for. Commented Nov 4, 2022 at 22:13
0

For this particular example, I would suggest that it conflicts with the author's intent, but also that it could well invalidate the answer. The question the answer is for also uses print h, which means that the answer using print h.keys() is appropriate, as it follows the same usage as the OP; using print (h.keys()) might have actually caused an error in the OP's environment (as they were quite possibly using Python 2). As someone not fluent in Python (and who has only ever used Python3), I don't know if print() and print are interchangeable in Python 2 (and 3), so don't take me as saying it would cause an error, just that in general it could if the syntax isn't valid Python 2 syntax.

If you encounter edits like this, I would suggest rejecting them. If an answer is needed/wanted that uses Python 3 syntax, rather than Python 2, then a new answer should be posted. If the question is specifically tagged for Python 2, then it might even be better than a new question for Python 3 is posted instead (which might refer to the Python 2 question and explain it doesn't work).

For something like the answer in question, a note being added to the answer would likely be better, something like:

In Python 3, use print (h.keys()) instead of print h.keys().

This doesn't conflict with the author's intent, doesn't invalidate, and instead offers an improvement to it.

5
  • 1
    Considering the downvotes, which in this case would suggest users disagreeing and the edit should be approved, it would be interesting to see an answer that explains the benefits of changing from print to print() from a meta perspective.
    – Thom A
    Commented Nov 4, 2022 at 14:15
  • 2
    If you see my comment above on the question the edit didn't really break anything Commented Nov 4, 2022 at 14:16
  • That it doesn't isn't relevant, @AbdulAzizBarkat . I am asking why people are therefore saying it should be approved as it improves the post.
    – Thom A
    Commented Nov 4, 2022 at 14:16
  • 1
    Note that the only reason why the question includes a print is because the OP added their solution into it based on the answer. FWIW, I have gone ahead and removed this part from the question since it does not belong there. Commented Nov 4, 2022 at 15:02
  • 3
    Not that it matters a ton, but print x and print(x) are interchangeable in Python 2 since they're the same as the parens are logically discarded. However, something like print x, y and print(x, y) are not the same as the first prints two items, and the second prints a tuple of two items. Commented Nov 4, 2022 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .