Sample

pyint-4fdef0dcce6b-I12

Inline all eligible single-use intermediate local variables

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 Pro16.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6360–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, inst, attr, value): if value is None: return self.validator(inst, attr, value) 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.502−6.753

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.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 is well-structured with clear logical organization: imports are grouped (standard library, typing, then project-specific), and the class uses the attrs decorator idiomatically. Nesting is minimal—only one level of indentation inside the method, with an early return for the None case that improves readability. Intent is clear: this is a validator wrapper that skips validation for None values and delegates otherwise. The __repr__ method is concise and informative. Code length is appropriate; every line serves a purpose. Action granularity is good—each statement is a single logical action. The early return avoids an else block, making the flow natural and easy to follow. Minor deductions: the `_OptionalValidator` name is slightly redundant with the module context, and `self.validator(inst, attr, value)` relies on background knowledge of attrs validator signatures, but this is idiomatic and acceptable in the attrs ecosystem.

Run 2

The code is generally readable with a clear, single-purpose class. Structure is logical, using the attrs decorator concisely to define fields and methods. Nesting is minimal—only one conditional, making control flow easy to follow. Intent is evident: the class wraps another validator to allow None values. Code length is appropriate for the task. Action granularity is good, with one logical action per line. Reading flow is natural, from imports to class definition, with methods ordered logically (dunder call, then repr). Minor deductions: the imports are not all used in the snippet (e.g., operator, re, Pattern, contextmanager), which slightly obscures relevance. The use of `@attrs(repr=False, ...)` conflicts with defining a custom `__repr__`, but this is not confusing enough to harm readability significantly. Overall, the code is clean and maintainable.

Run 3

The code is well-structured and readable. The imports are organized, the class uses the attrs decorator clearly, and methods are concise. Flat nesting, clear purpose, and appropriate length make it easy to understand. Minor deductions for relying on decorator magic without immediate context and a slightly terse check inside __call__, but overall very readable.

Run 1

Code Structure: The small class is logically organized, with validation behavior and representation in separate methods. Nesting: A single conditional and early return keep the code flat. Clarity of intent: The class name, None check, and delegation clearly express optional validation, though abbreviated parameter names and framework-specific decorators require some familiarity. Code length: The implementation is concise, but several imports are unused in the provided snippet and add clutter. Action granularity: Each line performs one clear action. Reading flow: Imports, class declaration, attribute definition, and methods follow a natural sequence; an additional blank line before the class would improve 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 and an early return keep control flow flat. Clarity of intent: The class name, None check, delegation, and descriptive repr clearly communicate optional validation; abbreviated parameters and framework-specific decorators require some context. Code length: The implementation is concise without unnecessary logic, but unused imports add clutter. Action granularity: Each statement performs a single clear action. Reading flow: The progression from declaration to validation behavior to representation is natural, with whitespace separating logical steps.

Run 3

Code Structure: The validator class is logically organized into its field, validation method, and representation method, although several unused imports add clutter. Nesting: Minimal nesting and an early return keep execution easy to follow. Clarity of intent: The class name, explicit None check, and delegation clearly express optional validation; familiarity with attrs and attrib is needed to understand field generation. Code length: The implementation is concise, with no unnecessary method logic, but the imports are excessive for this snippet. Action granularity: Each statement performs one clear action. Reading flow: The progression from declaration to validation behavior to representation is natural, aided by whitespace; a blank line between imports and the decorator would improve conventional formatting.