Sample

pyint-901c1a4292ff-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines21

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.7110–1; higher is more readable
Mi0.5080–1; higher is more readable
LLOC16Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol17.330–20; mean of three runs
BTTF0.5840–1; higher is more readable

Views

Source code

import operator import re from contextlib import contextmanager from re import Pattern from ._config import get_run_validators, set_run_validators from ._make import _AndValidator, and_, attrib, attrs from .converters import default_if_none from .exceptions import NotCallableError @attrs(repr=False, slots=True, unsafe_hash=True) class _OptionalValidator: validator = attrib() def __call__(self, date, step, total): if total is None: return self.validator(date, step, total) def __repr__(self): return f"<optional validator for {self.validator!r} or None>"

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.546.833−18.045
Source linesThe number of non-empty source lines.21+8.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.485−6.727

Intercept 8.87 + feature contributions = -7.503 (log-odds).
Score = sigmoid(-7.503) = 0.001.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.69+0.743
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.059+0.364
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.22+0.257
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.20.886−0.118
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 0.899 (log-odds).
Score = sigmoid(0.899) = 0.711.

Score0.508
Score16
Run 1

The code demonstrates generally clean structure with logical imports and a straightforward class definition using the attrs library. The class `_OptionalValidator` is concise and its purpose is clear: wrapping another validator to optionally run it when 'total' is not None. However, readability suffers from several issues: the `import` block is scattered with module-level re-imports (`Pattern`, `re`) that are not used within this snippet, creating ambiguity. The parameter names `date`, `step`, and `total` in `__call__` are vague and give no indication of expected types or meaning, reducing clarity of intent. Nesting is flat, which is good, and action granularity is okay—one meaningful action per line in the `__call__` method. The use of `__repr__` via f-string is clear. The overall reading flow is natural, but unused imports and opaque naming lower the score.

Run 2

The code is well-structured into logical imports, class definition, and clearly separated methods. The use of decorators and imports is clean. Nesting is minimal with only one conditional block. Intent is clear from the class name and method names. Code length is concise and appropriate for the functionality. Action granularity is good, with one action per line. Reading flow is natural, progressing from imports to class definition and then to methods. Minor deductions for the slightly opaque parameter names 'date', 'step', and 'total' in __call__, which might be clearer with different naming, and for the lack of type hints that could further improve readability.

Run 3

The code is generally readable but has some clarity issues. The class structure is logical and the use of attrs decorator is clean. However, several aspects reduce readability: the `__call__` method's parameter names (date, step, total) are misleading for a generic optional validator; the import of `operator` and `re` appears unused; the conditional early return in `__call__` creates a slightly awkward flow; and the purpose of `_OptionalValidator` isn't immediately evident from context alone. The nesting is minimal and line length is reasonable, but the semantic mismatch between parameter names and the generic validator purpose makes intent harder to grasp. The mixture of underscore-prefixed imports and public imports also hints at unclear module boundaries.

Run 1

Code Structure: Imports and a single focused class provide clear organization, though several imports are unused. Nesting: The early return keeps control flow flat and easy to follow. Clarity of intent: The class name and methods clearly express optional validation, but the parameter names date, step, and total obscure their roles in a generic validator. Code length: The implementation is concise, with unnecessary imports adding minor clutter. Action granularity: Each statement performs a single action. Reading flow: The progression from declaration to validation behavior to representation is natural; additional spacing between imports and the class would improve visual separation.

Run 2

Code Structure: The small class cleanly groups validation behavior and its representation, although numerous unused imports add clutter. Nesting: A single guard clause keeps execution flat and easy to follow. Clarity of intent: The class name, None check, and delegation clearly indicate optional validation, but the parameter names date, step, and total obscure their roles, and attrib() leaves the expected validator interface implicit. Code length: The implementation is concise, with no unnecessary logic; the import block is disproportionate to the shown functionality. Action granularity: Each statement performs one clear action. Reading flow: Imports, class declaration, callable behavior, and representation appear in a natural order, with whitespace separating concerns.

Run 3

Code Structure: The class is logically organized, though numerous unused imports add clutter. Nesting: A simple guard clause keeps control flow flat. Clarity of intent: The class name, None check, and representation clearly communicate optional validation, but parameter names date, step, and total obscure their roles in the validator interface. Code length: The implementation is concise; the import section is unnecessarily long for this snippet. Action granularity: Each statement performs a single clear action. Reading flow: Methods follow a natural progression from configuration to validation behavior to representation, although missing blank-line separation around the imports and class slightly reduces readability.