Sample

pyint-6c182fb0b78e-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines23

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7140–1; higher is more readable
Mi0.5080–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro12.330–20; mean of three runs
GPT-6.1 Sol14.670–20; mean of three runs
BTTF0.6270–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 not (value is None): pass else: 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.589.545−19.455
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.452−6.678

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

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.68.917+0.746
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.061+0.35
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.829−0.091
Indentation frequencyHow rapidly indentation changes from line to line.23+0.058

Intercept 0.07 + feature contributions = 0.914 (log-odds).
Score = sigmoid(0.914) = 0.714.

Score0.508
Score17
Run 1

The code is generally readable with clear structure and imports. However, the nested conditional in __call__ is unnecessarily convoluted - checking 'if not (value is None)' and doing nothing in that branch, then returning in the else, creates confusing logic flow when a simple 'if value is None: return' would suffice. The action granularity is reasonable, but the empty pass statement adds noise. The class structure, type hints, and naming are good, with clear intent for optional validation. The repr method is clean and informative. Overall, the code is readable but the conditional logic could be simplified to improve clarity and reduce cognitive load.

Run 2

The code has decent imports and class structure, but readability suffers in `__call__`. The `if not (value is None): pass else: return` is confusingly written — it could be simplified to `if value is None: return`, which would directly express intent without dangling pass/else and empty blocks. The action (`self.validator(...)`) is not clearly separated from the guard clause. The class overall is short and has a clear purpose as an optional validator. `__repr__` is straightforward. However, the odd conditional reduces clarity and adds needless lines. Nesting is minimal, action granularity is mostly one action per line except in the conditional where pass/return are stacked. Reading flow is interrupted by the unnatural conditional logic.

Run 3

The code structure is mostly logical, but the _OptionalValidator.__call__ method contains a confusing inversion of logic. Instead of checking 'if value is None: return', it uses an unnecessary 'if not (value is None): pass else: return' pattern that obscures the intent and adds noise. The nested conditional adds unnecessary depth. Action granularity is reasonable, with one action per line in the method body, but the empty 'pass' branch is a wasted line. The reading flow is interrupted by the awkward condition structure. Imports are clean and concise, and the dataclass-style validator shows reasonable organization. However, the core logic is unnecessarily convoluted, making the code harder to understand than it needs to be. A simpler early return pattern would significantly improve clarity.

Run 1

Code Structure: The class is logically organized, with validation and representation in separate methods, but numerous unused imports add clutter. Nesting: Nesting is shallow, although the if/pass/else pattern introduces unnecessary branching. Clarity of intent: The class name, validator attribute, and representation clearly convey optional validation; however, 'if not (value is None)' is less direct than an early return for None. Code length: The class is concise overall, but redundant control flow and unused imports make it longer than necessary. Action granularity: Each statement performs one action, making individual lines easy to follow. Reading flow: Imports followed by the class and its methods provide a natural progression, but the no-op branch interrupts the validation logic.

Run 2

Code Structure: The class is logically organized into its attribute, validation method, and representation method, but numerous unused imports add clutter. Nesting: Nesting is shallow, although the if/pass/else structure is unnecessary. Clarity of intent: The class name and representation clearly indicate optional validation, but `if not (value is None)` makes the condition harder to parse than a direct None check. Code length: The implementation is short, yet unused imports and the redundant branch make it longer than needed. Action granularity: Each line performs a single action, with no compressed statements. Reading flow: The class reads naturally overall, but the empty conditional branch interrupts the flow; an early return for None followed by validation would be clearer.

Run 3

Code Structure: The class is logically organized, with distinct validation and representation methods, but numerous unused imports add clutter. Nesting: Nesting is shallow, though the if/pass/else structure introduces unnecessary branching. Clarity of intent: The class name and representation clearly convey optional validation, but 'if not (value is None)' obscures a simple condition. Code length: The class is short, yet the conditional could be reduced to 'if value is None: return', and unused imports removed. Action granularity: Each line performs a single action, making individual operations easy to follow. Reading flow: Method order is natural, but the empty pass branch interrupts the flow before delegation to the underlying validator.