13

Questions like this one are caused by simple indentation issues in Python. IMO, they don't bring any value to the site and have more or less the same answer. What is the correct way to deal with them? I had previously hoped that the Roomba script will remove them. But after looking at the criteria for removal it seems unlikely as this question has answers (albeit with 0 scores).

If the question is more than 30 days old, and ...

  • has −1 or lower score
  • has no answers <===
  • is not locked

... or ...

  • it was closed and migrated to a different site

...or...

  • it was migrated from a different site, and then rejected

If the question is more than 365 days old, and ...

  • has a score of 0 or less, or a score of 1 and a deleted owner
  • has no answers <===
  • is not locked
  • has view count <= the age of the question in days times 1.5
  • has 1 or 0 comments
  • isn't on a meta site

Only this case seems to apply:

If the question was closed more than 9 days ago, and ...

  • not closed as a duplicate
  • has a score of 0 or less
  • is not locked
  • has no answers with a score > 0 <==
  • has no accepted answer
  • has no pending reopen votes
  • has not been edited in the past 9 days

But this requires the question to be closed. So what is the correct way to do it?

  • Should they be closed as duplicates to some another indentation related question?
  • Should they be flagged as "Not reproducible or was caused by a typo"?
  • Should a custom moderator flag be raised explaining the problem?
  • Or is it ok to leave them as it is? The OP receives their answer in the end.
2

2 Answers 2

20

IMHO, Python indentation errors generally should be closed as typos. Ideally, before an answer gets posted, so that they can be cleaned up by the Roomba. You can post a brief comment to let the OP know where the typo is.

However, Karl disagrees with my opinion, and he makes numerous valid points in his answer.

Don't close typos as duplicates: such duplicates are unlikely to help future readers. And definitely do not use a custom mod flag: mods cannot be domain experts on every language, so custom flags should not be used for language-related flaws on questions (or answers).


BTW, the question you linked doesn't have the generic tag so a lot of the regular Python answerers wouldn't have even seen that question when it was posted. It's a Good Idea to add that tag to good Python questions that don't have it, especially new ones. There's no point adding it now to that question, since it will soon be closed & manually deleted.

14
  • 2
    Ok got it. But (since it will soon be closed & manually deleted) if I understand correctly this question is being closed because attention to it was brought to it via this meta post... This question was asked 2 years and 9 months ago, I found it on 'First posts' queue because a low rep user had recently answered it. What should I do if I ever come across something like this again? Can I flag them as typos too?
    – Sabito
    Commented Jul 23, 2020 at 12:46
  • 4
    You can (and should) flag even older questions if the flag is applicable. The question isn't any less a typo-question just because it did not get noticed yet. Commented Jul 23, 2020 at 12:50
  • 1
    @Yatin Sure! A flag or close-vote will put the post into a review queue so it will get extra attention.
    – PM 2Ring
    Commented Jul 23, 2020 at 12:50
  • 4
    On one hand, if one has a gold badge, I think voting to close as dupe ASAP if no answers exist is the best option, because that'll prevent answers from being posted, and doesn't require additional moderation, and if downvoted, it'll roomba. On the other hand, if there are already answers, the roomba won't run if the question is closed as dupe, so VTC as typo could be better if no answers have been accepted/upvoted. Either way, if the roomba won't run, come back a couple days later and vote to delete the question Commented Jul 23, 2020 at 14:28
  • 2
    @CertainPerformance I do have a Python gold badge, but I don't use it to close typos. A question closed as a dupe is supposed to act as a signpost to its dupe target(s) for future readers, which is why they're kept (unless we already have plenty of similar signpost questions). But typos are rarely useful for future readers, which is why they get Roomba'd. If a typo question gathers an answer or two before it gets closed, it's no big deal, but I sometimes leave a brief comment on such answers. (BTW, the question quoted by the OP has now been manually deleted).
    – PM 2Ring
    Commented Jul 23, 2020 at 23:53
  • @PM2Ring Just because a question is not a good signpost for future readers doesn't mean it shouldn't be closed as a duplicate - the intent would be to get the question closed so as to prevent (useless) answers from being posted - and if a downvoted dupe has no answers, it will roomba. On the other hand, if you VTC as typo, that gives rep-hunters the chance to post an answer for those 5+ minutes before the question gets closed by 2 other close voters, and if said answer gets upvoted or accepted, the question will not roomba. So, I'd rather VTC as dupe ASAP, rather than give them that chance. Commented Jul 24, 2020 at 1:45
  • 1
    @CertainPerformance If it's actually a typo, then there shouldn't be any good dupe targets. I've had discussions (with other Python gold badge holders & mods) on the idea of using the dupe hammer to quickly close poor questions. The consensus is that it borders on abuse of the hammer privilege. So I'd prefer to close non-dupes through proper channels. And manually delete the question, if necessary. Hopefully, getting their answers deleted discourages some rep-hunters. ;)
    – PM 2Ring
    Commented Jul 24, 2020 at 3:25
  • For a few languages, there's a canonical question or two that exist for typos. If someone's whitespace is off, it's essentially a typo, but stackoverflow.com/q/45621722 happens to thoroughly explain the issue as well, so closing for that target would make perfect sense for a gold-badge holder. Similarly, for PHP, there's stackoverflow.com/q/18050071 , and so on. If such a canonical exists and if it addresses the core of the problem in the question, don't be afraid to close for it, even if said problem is basically a typo. Commented Jul 24, 2020 at 4:39
  • 1
    But such closures should only be performed if the target actually addresses the problem in the question, of course. No one should close as dupe if the dupe doesn't actually have anything to do with the question. Commented Jul 24, 2020 at 4:39
  • @CertainPerformance I'm familiar with that Q&A on Python indentation, I upvoted it & added it to the SO Python common questions collection. At the time, I posted a comment explaining why (IMHO) it should not be used as a dupe target, but that's been deleted. We discussed it in the SO Python chat room, you can see the transcript here. I can't stop people using it as a dupe target, but I'd prefer if they didn't.
    – PM 2Ring
    Commented Jul 24, 2020 at 12:25
  • Closing as a duplicate has many advantages: it promotes the canonical (which provides useful information, and deserves to come up in more search results); it's faster (I'm not inclined to care much about the charge of "abusive" in such clear-cut cases); and it covers the occasional case where people genuinely don't understand what the indentation requirements are. Commented Nov 4, 2022 at 5:54
  • @KarlKnechtel Sure, we do want to promote the canonicals. But we generally don't want to preserve questions that are ultimately just typos. OTOH, if the error is due to a genuine misunderstanding, and the question is reasonably clear (or can be made sufficiently clear by a minor edit), then I guess it may be a useful signpost.
    – PM 2Ring
    Commented Nov 4, 2022 at 6:39
  • 1
    It would be nice if closing questions as duplicates (especially of multiple targets) didn't tend to preserve them. OTOH, "number of times a question is linked as a duplicate" is a useful metric for figuring out which problems are most common. Commented Nov 4, 2022 at 6:42
  • 1
    @Karl The "problem" is that when we close a question as a dupe we aren't saying that the question is intrinsically bad, unlike the other closure reasons. Dupes should be preserved, unless we already have an adequate supply of similar signposts. If you don't want the question to be preserved, don't dupe-hammer it. As for linking to a relevant canonical, that can be done with a simple comment. True, the Linked questions aren't as prominent as the dupe links, but the SO devs may change that, as mentioned in the comments to the recent experiment in making Related questions more prominent.
    – PM 2Ring
    Commented Nov 4, 2022 at 6:53
4

First, the clearly bad options:

Should a custom moderator flag be raised explaining the problem?

Definitely do not bother moderators for something like this. There isn't, objectively, a problem that falls within their jurisdiction.

Or is it ok to leave them as it is? The OP receives their answer in the end.

In the case you cited, OP self-answered shortly after asking with the result of research; then years later, someone else came along with a new answer that was also completely wrong. So OP definitely did not "receive an answer" due to leaving the question open.

But more to the point, Stack Overflow is not about OP receiving an answer. It is about building a reference library. OP solving the problem is a nice bonus, and a great way to help keep people around - thus, part of the value of duplicate closures - but it is not at all our metric for proper handling.


Should they be closed as duplicates to some another indentation related question? Should they be flagged as "Not reproducible or was caused by a typo"?

These options need to be considered together, because the core question is: are these questions typos?

My argument is they are usually not typos; and as such, I wish to disagree very strenuously with the previously accepted answer.

My underlying premise: a typo is when the OP either doesn't pay attention to something that would already be clearly understood, or doesn't think about a problem using information and knowledge that is already clearly demonstrated.

But it is not a typo when OP encounters a problem due to not knowing something, no matter how trivial. Nor is it "unlikely to help others" if there are a lot of "others" who don't know that same thing.

So:

  1. In my experience reviewing hundreds (perhaps more than a thousand) of these questions, it has become abundantly clear that people often genuinely do not understand even the most basic ideas about how indentation is used in Python. (Sometimes one can't fathom how they expect Python to determine the block structure of the code; this is beside the point.) And yes, this includes people who are doing things like trying to make a website with Django, trying to snap together some pieces of an AI system with TensorFlow, etc. Python is quite probably the most popular language with the "in wayyy over their head" set.

  2. Also in my experience reviewing these questions—as well as potential canonicals—it has become abundantly clear that there are several fundamentally distinct ways of messing things up, and that these ways can be quite subtle (to the point where the site software itself interferes with attempts to produce a proper MRE).

    • An IndentationError can result from an empty block, and a correct understanding of the problem (and how to solve it) depends on whether it was intentional to have an empty block (or whether the next line of code was instead intended to be part of the block).

    • A try missing the corresponding except (or finally) can result in IndentationError: unexpected indent if the next part of the code is unindented past the try (which could make perfect sense if the except were present), but will give a generic SyntaxError when the next part is flush with the try. This was fixed only quite recently (somewhere between 3.9 and 3.11 inclusive) - now you can get a SyntaxError that explicitly explains the problem.

    • Most non-beginners know that mixed spaces and tabs are problematic. They might not realize how easy it is to end up with such code without realizing it. Editors do all kinds of strange, idiosyncratic things. Python 3 was supposed to make the rules a bit stricter, and give a clear, distinct TabError in cases of mixed indentation; but it doesn't consistently detect that a problem is caused by mixed indentation, and 2to3 could preserve whitespace that worked in 2.x but doesn't in 3.x. Wrongly indented code can "look right" in any number of ways (spaces before a tab are especially pernicious). In 2.x, valid code can "look wrong". Even in 3.x, there's a bizarre corner case of valid indentation that seems clearly wrong to me, that would look wrong if you set non-standard tab stops.

    • Relatedly: basically every "mixed spaces and tabs" question lacks a proper MRE in the post, even if OP provided one - because Stack Overflow itself converts the tabs to spaces. People who dismiss the problem as "oh, it must be a mixed-spaces-and-tabs situation" are almost always right, and having a Q&A about that for them to point to makes a ton more sense than having them get into an argument with OP about typos, or what keys were physically pressed to create the indentation. People who want to point out the specific issue, on the other hand, may have to open an edit view for the post. For older questions, they'd have to look at the original source of the post via the revisions interface - which isn't even in the site UI if there were no edits after the grace period.

    • Beginners often don't understand that Python is actually compiled, and thus IndentationError can't be caught by the same code that has the indentation problem, but it can be caught in exec'd code. Beginners may find this unintuitive because the problem is reported using the same mechanism as ordinary runtime errors (because they do happen at runtime for other code, within a metacircular evaluation context). They might not find information about this easily, because it isn't immediately apparent that IndentationError is a subtype of SyntaxError.

    • Even non-beginners who have a valid reason for execing code might genuinely not realize that the code can't start out indented. (Granted, in some cases it's on them for not noticing that the code was all indented; but either way the real underlying question is how to unindent it.)

    • Even then, one might wonder about how to dedent some copied-and-pasted code using an editor feature. And while looking through what seemed to be IndentationError questions, I found a lot of people who had problems related to trying to paste code into a REPL and not realizing the issues related to blank lines, or who somehow ended up with an interpreter trying to evaluate each line separately.

In short, there is a ton to learn about the topic.

Declaring that such issues are universally typos, is essentially arguing for the closure and ultimate deletion (or locking) of all the previous attempts at canonicals. I think it would be truly absurd to treat, in particular, the "main" canonical I'm getting an IndentationError (or a TabError). How do I fix it? that way - it's already been through the Meta wringer and had tons of work done, and it's very clearly answering actual questions - about problems that people have, commonly and reproducibly, due to a lack of understanding rather than a lack of attention or effort.


So: please ordinarily close such questions as duplicates. Of course, if OP says it's a typo (often in the form of a self-answer), it's a typo. To preempt some objections:

  • "The main canonical is a roll-up question!" - I disagree. Perhaps it should be edited to remove some things, but the core of it is quite coherent.

    • The signposts in the question are there specifically for the purpose of helping duplicate closers find better targets when that is necessary. It is usually not necessary.

    • Yes, a failure to understand the basic semantics of Python indentation can cause at least four distinct error messages as well as arbitrary logical errors if one is sufficiently unlucky. But it's still the same problem, with the same solution: you need to indent to mark the beginning of an "indented block" and dedent to mark the end, and this is done with leading whitespace that is interpreted according to a particular set of rules.

    • Please do use other canonicals, like some of the ones I linked above, for more specific problems. And of course if the OP's question about "fixing" the indentation is at the level of how to produce the desired text (rather than what text is desired), use e.g. How to fix Python indentation. But please do not choose a question simply because it's specific to the OP's error message. That doesn't help with understanding. A person who mistakenly over-indents makes fundamentally the same mistake as one who mistakenly under-indents, and needs fundamentally the same information.

    • I could see an argument for separating out the "mixed tabs and spaces that look correct" issue from the general issue of not understanding how much indentation to use or why. But as far as I know, we don't really have that canonical. No, IndentationError: unindent does not match any outer indentation level, although the indentation looks correct doesn't qualify IMO, because it's too heavily 2.x-oriented, is too vague ("mixed spaces and tabs" doesn't adequately explain what is and isn't allowed) and has way too many answers.

  • "Dupe-hammering a low-quality question isn't signalling the quality issue" - okay, so downvote it. If it's helping search engine users to find the canonical, it's doing its job.

  • "Dupe-hammered questions don't get Roomba'd" - frame challenge: why should they? They can't get new answers, they highlight the importance of the canonical, and they improve SEO. They should only be deleted when they mess up SEO by having wrong titles (especially "clickbait" ones that seem to describe a different problem someone could be searching for). If they have low-quality answers, ideally the answers should be deleted, so that the question can auto-redirect logged-out users. If they somehow have non-duplicate answers, typically one would prefer to preserve that information. (Of course, this is not realistic in the current case.)

    • Consider: getting the question Roomba'd as a typo requires three votes to close, dealing with answers, and then waiting. Getting the question deleted as a duplicate requires one gold-badge vote to close, waiting or downvoting, and then three votes to delete - paying no heed to any FGITW interference. Is the latter actually harder? Plus, it has the advantage of being more effective against such interference in the first place.
2
  • 1
    You make many good points...
    – PM 2Ring
    Commented Dec 23, 2023 at 12:38
  • 1
    I should hope I'd be able to, for how long I've spent on this one specific issue recently :) Commented Dec 24, 2023 at 9:22

You must log in to answer this question.

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