Sample

pyint-7687d21c0e3f-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines21

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.7090–1; higher is more readable
Mi0.5120–1; higher is more readable
LLOC16Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6040–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, ins, att, val): if val is None: return self.validator(ins, att, val) 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.503−6.754

Intercept 8.87 + feature contributions = -7.529 (log-odds).
Score = sigmoid(-7.529) = 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.06+0.355
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.871−0.118
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 0.889 (log-odds).
Score = sigmoid(0.889) = 0.709.

Score0.512
Score16
Run 1

The code is well-structured with clear imports and a focused class definition. Nesting is minimal—only one conditional inside __call__. Intent is clear: _OptionalValidator wraps another validator and skips validation for None values. The code is concise and avoids unnecessary length. Action granularity is good, with one meaningful operation per line in the __call__ method. Reading flow is natural, from imports to class definition to method implementations. Minor deductions: the class name starts with underscore but is used as a public-facing optional wrapper, which could be slightly ambiguous; the __call__ method could include a type hint for return value; and the conditional early return is simple but could be slightly more explicit with a comment explaining why None is skipped. Overall, very readable code that follows clean Python conventions and logical organization.

Run 2

The code is well-structured and readable. It uses short, focused imports and defines a single, clear class with two concise methods. Nesting is minimal (one level in __call__). Intent is clear: wrapping another validator to allow None. The class-level attribute declaration and decorator usage are idiomatic for attrs-based code. Methods are short, and each line performs one logical action. The reading flow is natural: import, class definition, attribute, logic, representation. Minor deductions: the purpose of the contextmanager and re imports is unclear since they are unused in this snippet, and the __call__ logic is simple but slightly redundant. Overall, the code is clean and maintainable.

Run 3

The code is well-structured with clear separation of imports and a single class definition. The nesting is minimal, with only one level inside the __call__ method. Intent is clear: an optional validator that skips validation when the value is None. The code is concise—no unnecessary methods or boilerplate. Each line performs a single action, and the flow follows a natural order: imports, class decorator, attribute, __call__ logic, and repr. The use of attrs decorators and type hints contributes to readability, while the short, descriptive names (_OptionalValidator, validator) make the purpose obvious. A minor deduction is the absence of a docstring explaining the class's role, which would help first-time readers.

Run 1

Code Structure: The validator is logically organized into a small class with distinct validation and representation methods, though several unused imports add clutter. Nesting: A single guard clause keeps control flow flat. Clarity of intent: The class name, None check, and delegation clearly express optional validation; abbreviated parameter names slightly reduce clarity. Code length: The class is concise, but the unused imports are unnecessary in this snippet. Action granularity: Each line performs one clear action. Reading flow: The progression from declaration to validation to representation is natural, with whitespace separating the main steps.

Run 2

Code Structure: Imports and the validator class are logically organized, although several imports are unused in this snippet. Nesting: Minimal nesting and an early return keep control flow flat. Clarity of intent: The class name, None check, delegated validation, and descriptive representation clearly communicate optional validation; abbreviated parameters ins, att, and val slightly reduce clarity. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs one action. Reading flow: Methods follow a natural sequence, and whitespace separates logical steps, though an additional blank line before the class would improve conventional Python formatting.

Run 3

Code Structure: The small class is logically organized into state, validation behavior, and representation, although several imports are unused in this snippet. Nesting: A single conditional with an early return keeps execution flat. Clarity of intent: The class name and methods clearly express optional validation, but abbreviated parameters (ins, att, val) and the attrs-based field declaration require some familiarity. Code length: The implementation is concise without unnecessary logic; unused imports add clutter. Action granularity: Each statement performs one action, making individual operations easy to follow. Reading flow: The progression from the validator field to handling None, delegating validation, and formatting a representation is natural.