Skip to content

Read three more shapes of code as literal blocks - #55

Merged
tamnd merged 1 commit into
mainfrom
block-openers-and-comments
Aug 18, 2026
Merged

Read three more shapes of code as literal blocks#55
tamnd merged 1 commit into
mainfrom
block-openers-and-comments

Conversation

@tamnd

@tamnd tamnd commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Closes #50.

L01 reports an entry whose translation is identical to its source. 5 of its 9 findings were entries there was nothing to translate in, so being identical was the correct answer and the check was reporting a classifier bug rather than a translation bug.

The rule was missing three shapes.

A block opener quoted without its body. There is no second line to be indented and no call to recognise, so every rule read it as a sentence ending in a colon.

def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):
case (Point(x1, y1), Point(x2, y2) as p2): ...
class Bag[T]: ...

A line with a comment on the end. The code is there, and the English on the end of it stopped any rule from seeing it.

parrot(1000)                                          # 1 positional argument
parrot()                     # required argument missing

A call whose arguments are quoted strings. What separates a call from a sentence here is spacing, code putting a space after a comma and nowhere else, and the spaces inside the quotes were being counted.

parrot('a million', 'bereft of life', 'jump')
Popen(["/usr/bin/git", "commit", "-m", "Fixes a bug."])

The keyword list

It stops where English starts. if, for, while, with and else open blocks and are also ordinary words, and a colon is how the documentation introduces a list. The wide list was measured before it was dropped: it reaches 4 more entries and 2 sentences, while a positional argument could be created like:: and if it is 3, implements::. Those two are in the tests as negatives. The comment rule wants two spaces before the hash, which is how PEP 8 says to write one and how every one of these in the corpus is written; one space reaches 2 more entries and reads a hash anywhere in a sentence as a comment.

Measured

before after
prose 75,660 75,593
literal_block 2,856 2,923
batches on a full run 2,802 2,801
human segments 1,299 1,294

67 entries move, 0.08 per cent of the corpus. That is small enough to read one at a time, and all 67 were read before this was written: no prose among them.

The 5 human segments that go are exactly the 5 L01 findings. They were translated by being copied, because copying was correct. human says who typed a string, not that the string wanted typing.

Checks

make check green, 1,399 tests, 97.45 per cent coverage, classify.py at 100 per cent. H03 clean.

L01 reports an entry whose translation is identical to its source, and 5 of
its 9 findings were entries there was nothing to translate in. The block rule
called them prose, so each one went to a model, came back unchanged because
unchanged was correct, and was then refused for being unchanged.

Three shapes were missing. A block opener quoted without its body has no
second line to indent and no call to recognise, which is
`def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):`. A line with a comment on
the end is code plus English and the English hid the code, which is
`parrot(1000)  # 1 positional argument`. And a call whose arguments are
quoted strings has spaces inside the quotes, and the spacing rule was
counting those as prose, which is `parrot('a million', 'bereft of life',
'jump')`.

The keyword list stops where English starts. `if`, `for`, `while`, `with` and
`else` open blocks and are also ordinary words, and a colon is how the
documentation introduces a list. Adding them reaches 4 more entries and 2
sentences, `while a positional argument could be created like::` and `if it
is 3, implements::`, so they are out and there are tests holding them out.
The comment rule wants two spaces before the hash, which is how PEP 8 says to
write one and how every one of these in the corpus is written.

67 entries move from prose to literal_block, 0.08 per cent of the corpus. 67
is small enough to read one at a time and all 67 were read: no prose among
them. One batch fewer on a full run.

5 of the 67 are entries somebody had already translated, and those 5 are
exactly what L01 was reporting. They leave the memory, because human says who
typed a string and not that the string wanted typing.
@tamnd
tamnd merged commit 539ef79 into main Aug 18, 2026
6 of 7 checks passed
@tamnd
tamnd deleted the block-openers-and-comments branch August 18, 2026 08:02
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

Successfully merging this pull request may close these issues.

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

1 participant