Skip to content

The literal block rule misses flush-left Python with no indent and no prompt #50

Description

@tamnd

is_literal_block needs a prompt, an indented line, or every line matching one of the code shapes. A block of Python that is flush left, one or two lines long, and made of call syntax rather than assignment or import matches none of the three, so it comes out as prose.

Found by L01 and L02, which flag these as untranslated English when they are code that was correctly copied:

File msgid
tutorial/controlflow.po:873 case (Point(x1, y1), Point(x2, y2) as p2): ...
tutorial/controlflow.po:1812 def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):
tutorial/controlflow.po:1349 parrot(1000) and five more calls, each with a trailing comment
tutorial/controlflow.po:1373 parrot() and three more, each with a trailing comment
whatsnew/3.10.po:1084 case (Point(x1, y1), Point(x2, y2) as p2): ...

_TIGHT rejects parrot(1000) # 1 positional argument because the trailing comment puts spaces outside a comma, which is the rule that separates sorted(d.keys()) from (Contributed by Eddie Elizondo in :issue:35810.) and is worth keeping. def f(...) and case (...) are not calls at all, so nothing looks at them.

Two shapes would cover every one of these:

  • A line that opens a block: def, class, case, match, if, for, while, with, try followed by a space and ending in a colon or a colon and an ellipsis.
  • A trailing # comment on a line that is otherwise code, by testing the part before the # against the existing rules rather than the whole line.

Both are whole-line anchors and both have to be measured against the corpus before landing, the same way the rules already there were. The risk is the one the module docstring names: a paragraph mistaken for code is an English sentence left in a Vietnamese page, and if and for are also English words.

Seven of the nine L01 findings and six of the 144 L02 findings go away when this lands. The remaining L01 entries are the three copyright lines, which are a policy question rather than a classifier one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is wrongsegmentationMarkup protection, classification, batching

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions