Sample

pyint-8bc519db9bb8-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines23

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8370–1; higher is more readable
Mi0.2780–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5980–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, ins, att, val): """ We use a callable class to be able to change the ``__repr__``. """ if len(val) > self.max_length: msg2 = f"Length of '{att.name}' must be <= {self.max_length}: {len(val)}" raise ValueError(msg2) 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.623−6.935

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.84.833+0.564
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.455
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.802−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.84.958+0.067
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 1.639 (log-odds).
Score = sigmoid(1.639) = 0.837.

Score0.278
Score17
Run 1

The code is generally readable with clear structure and intent. It uses a frozen attrs class for a validator, which is logical and concise. The __call__ method has a single conditional with one action, keeping nesting flat. However, a few minor issues reduce clarity: the variable name 'msg2' is oddly numbered (suggesting leftover from refactoring), the unused imports (operator, re, Pattern, contextmanager, get_run_validators, set_run_validators, _AndValidator, and_, default_if_none, NotCallableError) add noise and obscure actual dependencies. The docstring is helpful but could explain the class purpose rather than just noting repr customization. Overall, logic is easy to follow, but cleaning up imports and renaming 'msg2' would improve readability.

Run 2

The code demonstrates strong readability through its logical structure and clear intent. The class-based validator approach is well-organized, with distinct methods for validation and representation. Nesting is minimal, with only a single conditional inside the __call__ method. The code is concise but includes enough context via imports and decorators to understand its purpose. Each method performs a single, clear action, and the reading flow is natural—from class definition to validation logic to representation. Minor deductions: the variable name 'msg2' is slightly ambiguous (why '2'?), and the __call__ method's docstring could provide more context about its usage. Overall, the code is easy to follow, maintain, and understand.

Run 3

The code is well-structured and readable. It uses clear imports, a focused class with a single responsibility, and descriptive naming. The nesting is minimal, with only one conditional inside the __call__ method. The intent is clear: validating maximum string length. The code is concise and avoids unnecessary length. Action granularity is appropriate, with one logical action per line. Reading flow is natural, following a logical progression from imports to class definition to method implementations. Minor deductions could be made for the slightly ambiguous variable name 'ins' and 'att' in the method signature, which could be more descriptive, and the abbreviated variable name 'msg2' which could be simplified to 'msg'. The docstring is helpful and the __repr__ method provides useful information. Overall, this is clean, maintainable code that follows good practices.

Run 1

Code Structure: The validator is logically organized into configuration, validation, and representation methods, though numerous unused imports add clutter. Nesting: A single conditional keeps nesting minimal. Clarity of intent: The class name, max_length attribute, and error message clearly communicate the purpose; abbreviated parameters and the name msg2 reduce clarity slightly. Code length: The implementation is concise, but unused imports are unnecessary. Action granularity: Each statement performs one clear action. Reading flow: The class reads naturally from setup to behavior to representation, although the __call__ docstring explains the class design rather than the method's validation behavior.

Run 2

Code Structure: The validator class is logically organized into configuration, validation, and representation methods. Nesting: A single conditional keeps execution easy to follow. Clarity of intent: The class name, max_length attribute, and error message clearly communicate length validation, though ins, att, val, and msg2 are less descriptive, and the docstring explains representation rather than validation. Code length: The implementation is concise, but several imports are unused in the provided snippet. Action granularity: Each line performs one clear action. Reading flow: Methods follow a natural order, with straightforward validation and exception handling; minor naming and import cleanup would improve readability.

Run 3

Code Structure: Imports and a small validator class are logically organized, although several imports are unused in this snippet. Nesting: Only one conditional keeps the code flat and easy to follow. Clarity of intent: The class name, max_length attribute, and error message clearly communicate length validation; abbreviated parameters and the name msg2 are less descriptive. The docstring explains the callable-class design rather than the method's validation behavior. Code length: The implementation is concise with little unnecessary code beyond unused imports. Action granularity: Each line performs a single clear action. Reading flow: Declaration, validation, and representation follow a natural order, though an additional blank line before the class would improve visual separation.