Sample

pyint-2d3aa91488fa-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines27

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8850–1; higher is more readable
Mi0.6620–1; higher is more readable
LLOC20Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol17.330–20; mean of three runs
BTTF0.670–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 _OrValidator: validators = attrib() def __call__(self, inst, attr, value): for v in self.validators: try: v(inst, attr, value) except Exception: # noqa: BLE001, PERF203, S112 continue else: return msg = f"None of {self.validators!r} satisfied for value {value!r}" raise ValueError(msg) def __repr__(self): return f"<or validator wrapping {self.validators!r}>"

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.664.856−21.94
Source linesThe number of non-empty source lines.27+10.8
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.504−6.755

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

Feature contributions

FeatureValueContribution
(log-odds)
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.73.929+0.534
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.051+0.446
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.74+0.39
Indentation frequencyHow rapidly indentation changes from line to line.26+0.162
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.27+0.08
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.26.773−0.036

Intercept 0.07 + feature contributions = 2.045 (log-odds).
Score = sigmoid(2.045) = 0.885.

Score0.662
Score20
Run 1

The code is well-structured with clear imports and a single, focused class definition. It uses the attrs library effectively to reduce boilerplate. The _OrValidator class has a logical organization with distinct methods for call logic and representation. Nesting is minimal with only one loop and try/except block inside the __call__ method. Intent is clear: validate if any validator in a list passes. Code length is concise and appropriately sized for the functionality. Action granularity is generally good, though the try/except/else block could be slightly clearer. Reading flow is natural with a clear progression from class definition to method implementations. The main readability concerns are the single-letter variable 'v' and the dense try/except/else block in __call__, which could benefit from a helper method or more explicit control flow. Overall, this is readable code that follows common Python patterns.

Run 2

The code is well-structured and readable. The import section is organized, the class has a clear single responsibility, and the `__call__` method follows a flat, logical flow. Nesting is minimal (one loop with try/except/else), and the intent of validating against multiple validators with an 'or' relationship is evident. Action granularity is appropriate, with one main action per line. The code length is concise and avoids unnecessary verbosity. Reading flow is natural, following the validation logic from first validator to final fallback error. Minor deductions: the catch-all exception handler could be more specific but is justified for validator semantics; the `else` clause on the loop is slightly non-intuitive for less experienced readers.

Run 3

The code is well-structured with clear class and method organization. Nesting is minimal with only one level inside the __call__ method's loop. Intent is obvious: an OR validator that tries multiple validators and raises if none pass. Code is concise but maintains readability. Action granularity is appropriate - the try/except/else block handles exception flow cleanly on separate lines. Reading flow is natural and logical. Minor deductions: the exception handling with multiple noqa comments could be clearer about which specific exceptions are expected, and the class inherits from attrs with Python 3.7+ decorator syntax which assumes familiarity with the library, but overall this is highly readable code with good structure and clear intent.

Run 1

Code Structure: The small validator class is logically organized, with validation and representation separated; several unused imports add clutter. Nesting: The loop and try/except/else introduce moderate but manageable nesting. Clarity of intent: The class name, validators attribute, and error message clearly convey that any validator may succeed, though the abbreviated name v and broad exception handling obscure which failures are intentionally suppressed. Code length: The implementation is concise, but the imports are excessive for this snippet. Action granularity: Each line generally performs one action, making execution easy to follow. Reading flow: Validation proceeds naturally from trying each validator to returning on success or raising after all fail; decorator configuration and lint-suppression annotations add minor visual noise.

Run 2

Code Structure: The validator class is logically organized, separating validation behavior from representation, though several imports are unused in this snippet. Nesting: The loop and try/except/else introduce moderate but manageable nesting. Clarity of intent: The class name, validators attribute, and error message clearly express OR-style validation; the abbreviated names v, inst, and attr slightly reduce clarity. Catching every Exception obscures which failures are intended to indicate unsuccessful validation. Code length: The implementation is concise without unnecessary logic. Action granularity: Each line generally performs one action. Reading flow: Validation proceeds naturally through alternatives, returns on success, and raises after all fail. The decorator options and lint-suppression codes add some visual noise.

Run 3

Code Structure: The class is logically organized, separating validation behavior from representation. Nesting: The loop and try/except/else add moderate nesting, but the early return keeps control flow manageable. Clarity of intent: Names and the failure message clearly communicate that any wrapped validator may satisfy validation; however, the abbreviated name 'v' and broad exception handling obscure some details. Code length: The implementation is concise, though numerous imports are unused in the shown snippet and add clutter. Action granularity: Each line generally performs one action, with no compressed statements. Reading flow: Execution flows naturally from trying validators to returning on success or raising after all fail. The dense suppression comment and framework-specific decorator slightly interrupt readability.