Sample

pyint-df47ebf2ff08-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines25

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7870–1; higher is more readable
Mi0.6730–1; higher is more readable
LLOC18Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5760–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, frozen=True, slots=True) class _NumberValidator: bound = attrib() compare_op = attrib() compare_func = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not self.compare_func(value, self.bound): raise ValueError((f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}")) def __repr__(self): return f"<Validator for x {self.compare_op} {self.bound}>"

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.646.656−21.34
Source linesThe number of non-empty source lines.25+10
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.576−6.864

Intercept 8.87 + feature contributions = -9.334 (log-odds).
Score = sigmoid(-9.334) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.96+0.744
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.95.923−0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.057+0.385
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.26+0.116
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.24.722−0.064
Indentation frequencyHow rapidly indentation changes from line to line.23+0.058

Intercept 0.07 + feature contributions = 1.31 (log-odds).
Score = sigmoid(1.31) = 0.787.

Score0.673
Score18
Run 1

The code is well-structured and readable. The import section is organized, and the class uses a decorator with clear configuration. The constructor-like attributes are explicit, and the __call__ method has a single, clear responsibility with a helpful comment explaining the design choice. The f-string error message is concise and informative, and the __repr__ method provides a clean summary. Minor deductions include the unnecessary blank line immediately after the if statement and the slightly long error message line, which could be wrapped for better readability. Overall, the code demonstrates clear intent, good granularity, and a natural reading flow.

Run 2

The code is generally readable with a clear structure: imports organized, class decorators concise, and a single-purpose validator class. It uses attrs to reduce boilerplate and keeps nesting minimal. However, a few issues lower the score: the class's intent relies on external knowledge of attrs, and some names (e.g., compare_op vs compare_func) are slightly ambiguous. The error message f-string spans two lines awkwardly, and the __repr__ uses 'x' rather than a meaningful placeholder. The method __call__ is short but splits one logical action across lines. Overall, the code is concise but could improve clarity of intent and formatting.

Run 3

The code is well-structured and follows clean design principles. It uses a frozen, slotted attrs class for immutability and memory efficiency. The class has a single clear responsibility: validating numeric values. Naming is descriptive (_NumberValidator, compare_op, compare_func), and methods are concise. Nesting is minimal — one conditional inside __call__. The docstring explains the unusual choice of a callable class. The only minor issue is the blank line after the if statement, which slightly interrupts flow, and the f-string is long but still readable. Overall, intent is clear and the code is concise, flat, and maintainable.

Run 1

Code Structure: Imports and a small validator class are logically organized, although several imports are unused in this snippet. Nesting: Minimal nesting makes the validation path easy to follow. Clarity of intent: Descriptive field names, the comparison check, and the error message clearly convey bounded-number validation; however, the __call__ docstring explains the class representation rather than the method's behavior. Code length: Concise overall, with unnecessary parentheses around the error message and an extra blank line before the raise. Action granularity: Each statement performs a single action. Reading flow: Fields, validation, and representation appear in a natural order, though the long raise statement and minor whitespace issues slightly interrupt readability.

Run 2

Code Structure: The validator is logically organized into attributes, validation behavior, and representation, though several unused imports add clutter. Nesting: A single conditional keeps nesting shallow. Clarity of intent: Descriptive attribute names and the error message make the numeric-bound validation clear, but the docstring explains the callable-class design rather than the validation behavior. Code length: The implementation is concise; unused imports, an empty line before the exception, and redundant parentheses are unnecessary. Action granularity: Each statement performs one clear action. Reading flow: The class reads naturally from configuration to validation to representation, with minor formatting distractions.

Run 3

Code Structure: The small validator class is logically organized, with attributes followed by validation and representation methods. Nesting: Minimal nesting makes control flow easy to follow. Clarity of intent: Descriptive names and the error message clearly communicate numerical bound validation, though the docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise, but several imports are unused in this snippet, and the extra parentheses around the error message are unnecessary. Action granularity: Each statement performs a single action. Reading flow: The class reads naturally, although the blank line before the raise statement and the long exception line slightly disrupt flow.