Sample

pyint-e2ffd6356385-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines23

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8310–1; higher is more readable
Mi0.260–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6170–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 _MaxLengthValidator: max_length = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if len(value) > self.max_length: msg = f"Length of '{attr.name}' must be <= {self.max_length}: {len(value)}" raise ValueError(msg) def __repr__(self): return f"<max_len validator for {self.max_length}>"

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.578.587−19.093
Source linesThe number of non-empty source lines.23+9.2
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.609−6.914

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.917+0.598
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.46
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.24+0.187
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.22.784−0.091
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.86.958−0.018
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 1.592 (log-odds).
Score = sigmoid(1.592) = 0.831.

Score0.26
Score17
Run 1

The code is well-structured and highly readable. It imports only what is needed, defines a single focused class with a clear purpose, and keeps nesting minimal (one level inside __call__). The validation logic is straightforward: check length, raise error with a clear message. The custom __repr__ method enhances debugging. Naming is descriptive, and the docstring clarifies the design choice. The class is concise without unnecessary verbosity, and each logical action is separated naturally. Minor deductions: some imports like operator, re, and Pattern appear unused, and the overall module lacks context, but within the given snippet, readability is strong.

Run 2

The code is well-structured and highly readable. It uses a clear class-based validator with a focused single responsibility. The `@attrs` decorator with `frozen=True` and `slots=True` is concise and communicates immutability and memory efficiency. Nesting is minimal, with only one conditional block inside the `__call__` method. Naming is descriptive (`_MaxLengthValidator`, `max_length`, `inst`, `attr`, `value`) and the docstring explains the design choice of using a callable class. Action granularity is appropriate: the length check, message formatting, and exception raising are separated into distinct lines. The reading flow is natural, moving from construction (decorator) to logic (validation) to representation (`__repr__`). Minor deductions could be made for the unused imports and the private naming with a leading underscore, which slightly obscures intent if this class is meant to be used externally.

Run 3

The code is highly readable. Structure is logical: imports, a single decorated class, one clear method, and a repr. Nesting is minimal with only a single if statement. Intent is explicit — a frozen, slotted validator enforcing maximum length. The class-based validator pattern is idiomatic for attrs, and the docstring explains the rationale concisely. Code length is appropriate; no unnecessary lines or overly dense constructs. Action granularity is clear, with one logical action per statement. Reading flow is natural: decorators, fields, call logic, error raising, then repr. Minor deductions: the `msg` variable could be inlined without hurting clarity, and the docstring, while useful, breaks the otherwise very tight flow. Still, this is an excellent balance of brevity and clarity.

Run 1

Code Structure: Imports, class configuration, validation logic, and representation are logically organized, although several imports are unused in this snippet. Nesting: Minimal nesting, with only one conditional inside the validation method. Clarity of intent: The class name, max_length attribute, and descriptive error message make the purpose clear; the __call__ docstring explains the callable-class design rather than the validation behavior. Code length: Concise overall, though unused imports add clutter and len(value) is computed twice on failure. Action granularity: Each line performs a single clear action. Reading flow: Natural progression from configuration to validation to representation, with appropriate spacing between methods; an additional blank line before the top-level class would improve conventional formatting.

Run 2

Code Structure: Imports and a small, focused validator class are logically organized, though several imports are unused in this snippet. Nesting: Minimal nesting makes control flow easy to follow. Clarity of intent: Descriptive names and the explicit length comparison clearly communicate validation behavior; the docstring explains the callable-class design rather than the method's function. Code length: Concise, with little unnecessary code beyond unused imports. Action granularity: Each statement performs one clear action, and error-message construction is separated from raising the exception. Reading flow: The progression from configuration to validation to representation is natural, although framework-specific decorators and attribute declarations require some background knowledge.

Run 3

Code Structure: The validator is logically organized into configuration, validation, and representation methods, although numerous unused imports add clutter. Nesting: A single conditional keeps the code flat and easy to follow. Clarity of intent: Descriptive class and attribute names, a direct length comparison, and an informative error message clearly communicate the purpose; the callable-class docstring explains the design rather than validation behavior. Code length: The implementation is concise, but the imports are excessive for this snippet. Action granularity: Each line performs one clear action, with error construction separated from raising the exception. Reading flow: The sequence from class declaration to validation and representation is natural; additional blank lines around the class would improve visual separation.