Sample

pyint-923a679a0535-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines31

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.810–1; higher is more readable
Mi0.650–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro10.670–20; mean of three runs
GPT-6.1 Sol13.330–20; mean of three runs
BTTF0.5420–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 _MatchesReValidator: pattern = attrib() match_func = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not (not self.match_func(value)): pass else: msg = f"'{attr.name}' must match regex {self.pattern.pattern!r} ({value!r} doesn't)" raise ValueError( msg, attr, self.pattern, value, ) def __repr__(self): return f"<matches_re validator for pattern {self.pattern!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.693.078−22.872
Source linesThe number of non-empty source lines.31+12.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.348−6.522

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

Feature contributions

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

Intercept 0.07 + feature contributions = 1.448 (log-odds).
Score = sigmoid(1.448) = 0.81.

Score0.65
Score19
Run 1

The code has a clear overall structure and uses a class-based validator, which is logical. However, readability is significantly hurt by the awkward `if not (not self.match_func(value)): pass else:` block, which should be a simple inversion or direct condition. It introduces unnecessary nesting and obscures intent. The `__call__` method mixes validation logic with error construction, though the error is clearly formatted. Naming is mostly clear (`_MatchesReValidator`, `match_func`, `pattern`), but abbreviations like `inst` and `attr` slightly reduce clarity without context. The class is concise but the conditional negations make it hard to follow. Line-level granularity is okay, but the conditional flow disrupts natural reading. Overall, the code is maintainable but needs cleanup of the core condition and a more direct expression of validation failure.

Run 2

The code has a clear purpose and uses modern Python features like attrs and type hints, which aid readability. However, there are several issues. The conditional logic in `__call__` is convoluted and redundant: `if not (not self.match_func(value))` followed by `pass` and an `else` block is unnecessarily confusing and should be simplified to `if self.match_func(value) is None:` or similar. The docstring is helpful but the error message construction is verbose. The class structure is logical, but the action granularity is inconsistent—multiple arguments are spread across lines unnecessarily. The imports are somewhat cluttered, and the `operator` and `re` imports appear unused, adding noise. Overall, the code is functional but could be much clearer with simpler conditionals, cleaner error raising, and removal of unused imports.

Run 3

The code is somewhat readable but has notable issues. The structure is logical overall, and using a frozen/slotted attrs class is clean. However, the `if not (not self.match_func(value)): pass else: raise` construction is confusing and adds unnecessary nesting with a double negative — it should be inverted to `if self.match_func(value) is None: raise`. Intent is not immediately clear due to this odd condition. Line length is mostly reasonable, though the f-string message is verbose. Action granularity is acceptable but the `pass` branch is redundant and breaks flow. Importing `Pattern` and unused imports like `operator`, `re`, `contextmanager`, and several attrs helpers lowers clarity and signals possible code bloat. The `__repr__` is fine. Overall, it reads as if it was auto-refactored or minimally edited, leaving behind artifacts that reduce readability.

Run 1

Code Structure: The small validator class is logically organized, although several unused imports add clutter. Nesting: Nesting is shallow, but the empty success branch and else block unnecessarily complicate a simple validation check. Clarity of intent: Class and attribute names, the error message, and __repr__ communicate the purpose well; however, the double negation in `if not (not self.match_func(value))` obscures the condition, and the __call__ docstring explains representation rather than validation behavior. Code length: Mostly concise, but unused imports and the pass branch are unnecessary. Action granularity: Statements generally perform one action per line, and the multiline exception construction is easy to scan. Reading flow: The class reads naturally overall, but the inverted conditional interrupts the straightforward check-and-raise flow.

Run 2

Code Structure: The validator class is logically organized, with attributes, validation, and representation separated, but numerous unused imports add clutter. Nesting: Nesting is shallow, although the empty success branch and else block introduce unnecessary structure. Clarity of intent: Names and the error message communicate regex validation clearly, but the double negation obscures the condition, and the docstring explains the callable-class design rather than the method's behavior. Code length: The snippet is short, yet unused imports, pass, and the redundant conditional make it longer than necessary. Action granularity: Each line generally performs one action, and the exception arguments are clearly separated. Reading flow: The class reads naturally overall, but the inverted conditional interrupts comprehension; directly checking if not self.match_func(value) and raising the error would improve readability.

Run 3

Code Structure: The validator is logically organized into attributes, validation, and representation methods, though numerous unused imports add clutter. Nesting: Nesting is shallow, but the empty success branch and else unnecessarily complicate a simple failure check. Clarity of intent: Class and attribute names communicate regex validation, and the error message is informative; however, the double negation obscures the condition, and the __call__ docstring explains the callable-class design rather than the method's behavior. Code length: Mostly concise, but redundant control flow and unused imports increase length without benefit. Action granularity: Statements generally perform one action each, and the multiline exception arguments are easy to distinguish. Reading flow: The overall progression is natural, but 'if not (not ...): pass' interrupts comprehension; directly checking 'if not self.match_func(value)' would improve readability.