Sample

pyint-58a950acc281-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines27

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8410–1; higher is more readable
Mi0.6950–1; higher is more readable
LLOC20Logical lines; fewer is more readable
DeepSeek V4 Pro11.330–20; mean of three runs
GPT-6.1 Sol130–20; mean of three runs
BTTF0.5480–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 _NumberValidator: bound = attrib() compare_op = attrib() compare_func = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not (not self.compare_func(value, self.bound)): pass else: msg = f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}" raise ValueError(msg) def __repr__(self): return f"<Validator for x {self.compare_op} {self.bound}>"

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.696.341−22.979
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.533−6.8

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.79.036+0.471
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.056+0.398
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.81.929+0.195
Indentation frequencyHow rapidly indentation changes from line to line.25+0.128
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.28+0.045
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.26.783−0.035

Intercept 0.07 + feature contributions = 1.668 (log-odds).
Score = sigmoid(1.668) = 0.841.

Score0.695
Score20
Run 1

The code is highly unreadable due to a deliberately convoluted conditional: 'if not (not self.compare_func(value, self.bound)): pass else: raise...' This double negative with an empty pass block obscures the logic, violating the clarity of intent and action granularity criteria. The import of operator, re, Pattern, and contextmanager are unused. The class and attribute names are reasonable, and the docstring explains the callable class choice, but the core validation method is poorly structured. The use of attrs is standard, but the overall structure suffers from unnecessary complexity (e.g., importing decorators not used). The conditional can be simplified to 'if self.compare_func(value, self.bound): raise...', which would be much clearer. As written, it forces the reader to mentally untangle the logic, creating confusion and reducing maintainability.

Run 2

The code is logically organized and makes use of clear class attributes, but it suffers from unnecessary verbosity, particularly in the __call__ method. The conditional `if not (not self.compare_func(value, self.bound)): pass else: raise...` is convoluted and should be simplified to `if self.compare_func(value, self.bound): raise...`. This impacts clarity and reading flow. Nesting is minimal, action granularity is generally one action per line, and the intent of the class is understandable, but the awkward conditional logic creates ambiguity. The docstring is helpful but the code length and structure in the validator method reduce overall readability.

Run 3

The code is generally clear but has a few readability issues. Structure is logical, with a single class encapsulating validator behavior, and nesting is minimal. However, the `__call__` method uses an awkward `if not (not ...): pass else:` construct, which obscures intent and should simply be `if self.compare_func(value, self.bound): raise ...`. Action granularity is mostly fine, but the conditional check splits a single logical step. Imports are clean and purposeful. The docstring and `__repr__` add clarity. Overall, concise but the conditional hurts the reading flow and clarity of intent.

Run 1

Code Structure: The validator class is logically organized, with separate validation and representation methods, but numerous unused imports add clutter. Nesting: Nesting is shallow, although the pass/else branch introduces unnecessary control flow. Clarity of intent: Attribute names and the error message communicate numeric-bound validation, but the double negation obscures the comparison, and the __call__ docstring explains representation rather than validation. Code length: The class is compact, but unused imports and the redundant conditional make it longer than necessary. Action granularity: Statements generally perform one action per line. Reading flow: The class reads naturally overall, but the inverted-looking condition and empty success branch interrupt comprehension; directly raising when the comparison fails would improve readability.

Run 2

Code Structure: The callable validator class logically groups its attributes, validation behavior, and representation, but numerous unused imports add clutter. Nesting: Nesting is shallow, though the empty success branch and else block unnecessarily complicate control flow. Clarity of intent: Attribute names and the error message communicate the numeric comparison, but the double negation obscures the condition; the docstring explains the callable-class choice rather than validation behavior. Code length: The snippet is short, but unused imports and the redundant pass branch make it longer than necessary. Action granularity: Each line generally performs one action, and message construction is separated from raising the exception. Reading flow: Class organization is natural, but the inverted-looking condition interrupts comprehension. A direct 'if not self.compare_func(value, self.bound)' followed by the error handling would be substantially clearer.

Run 3

Code Structure: The validator class is logically organized, with attributes, validation, and representation separated, but numerous unused imports add clutter. Nesting: Depth is shallow, although the if/pass/else structure is unnecessary. Clarity of intent: Names and error messages communicate numeric-bound validation clearly, but the double negation obscures the condition, and the __call__ docstring explains representation rather than validation. Code length: The class is short, yet redundant branching and unused imports make it longer than necessary. Action granularity: Statements generally perform one action per line. Reading flow: The class follows a natural sequence, but the inverted condition and empty success branch interrupt comprehension; a direct failure check would read more naturally.