Sample

pyint-553528dcf51e-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines29

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.80–1; higher is more readable
Mi0.4010–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5710–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 self.match_func(value): raise ValueError( (f"'{attr.name}' must match regex {self.pattern.pattern!r} ({value!r} doesn't)"), 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.643.4−21.232
Source linesThe number of non-empty source lines.29+11.6
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.385−6.578

Intercept 8.87 + feature contributions = -7.34 (log-odds).
Score = sigmoid(-7.34) = 0.001.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97+0.761
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.97−0.443
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.052+0.438
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.27+0.197
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.30−0.026
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.28.684−0.009

Intercept 0.07 + feature contributions = 1.385 (log-odds).
Score = sigmoid(1.385) = 0.8.

Score0.401
Score17
Run 1

The code is highly readable with clear structure and intent. It uses a frozen, slotted attrs class for an immutable validator, which is logical and concise. The `__call__` method is flat, with a single conditional and a clear error message. Naming is explicit (`_MatchesReValidator`, `match_func`, `pattern`). Action granularity is appropriate—each significant step is on its own line. The only minor deductions are for an unnecessary blank line inside the `if` block and the slightly verbose f-string, which could be clearer with line breaks. Overall, the reading flow is natural and the logic is easy to follow.

Run 2

The code is generally readable with clear structure and purpose. It uses a frozen attrs class as a validator, and the docstring explains the design choice. Naming is descriptive (_MatchesReValidator, match_func). The __call__ method is flat and concise, with one primary action plus error construction. The __repr__ is clear. Minor deductions: an unnecessary blank line inside __call__, and the error message f-string is slightly dense. The import block is somewhat cluttered with unused imports (operator, re, Pattern, contextmanager, get_run_validators, etc.), which reduces clarity. Overall, intent is understandable and flow is natural, but tidier imports and minor formatting would improve readability.

Run 3

The code is generally readable with a clear class structure, minimal nesting, and good use of type hints and docstrings. It follows logical organization with a single responsibility for the class. The blank line after the conditional is slightly awkward, and the error message formatting is dense but acceptable. The use of attrs decorators keeps the code concise. However, the purpose of match_func and pattern attributes could be clearer with more descriptive names or type annotations. The repr method is straightforward. Overall, the code demonstrates good readability with minor improvements possible in formatting and naming clarity.

Run 1

Code Structure: The validator is logically organized into attributes, validation behavior, and representation, although numerous unused imports add clutter. Nesting: A single conditional keeps nesting shallow. Clarity of intent: Descriptive class and attribute names make regex validation clear, but the __call__ docstring explains the callable-class design rather than validation behavior. Code length: The implementation is concise, though redundant parentheses around the error message and an empty line before the raise are unnecessary. Action granularity: Each statement performs one clear action, and the exception arguments are neatly separated. Reading flow: Methods follow a natural order, but import clutter, limited spacing before the class, and the stray blank line slightly interrupt readability.

Run 2

Code Structure: The validator class is logically organized, with attributes, validation behavior, and representation clearly separated, though several imports are unused in this snippet. Nesting: A single conditional keeps nesting shallow. Clarity of intent: Class and attribute names make regex validation clear, but the __call__ docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise; redundant parentheses around the error message and an extra blank line add minor clutter. Action granularity: Each statement performs one clear action, and the exception arguments are laid out separately. Reading flow: The progression from configuration to validation to representation is natural, although the blank line before raise slightly interrupts it.

Run 3

Code Structure: The validator is logically organized into attributes, validation behavior, and representation, though several unused imports add clutter. Nesting: A single conditional keeps the code shallow and easy to follow. Clarity of intent: Class and attribute names clearly communicate regex validation, and the error message is informative; however, the __call__ docstring explains the class design rather than the method's behavior. Code length: The implementation is concise, but unnecessary parentheses around the error-message f-string and an extra blank line reduce polish. Action granularity: Each statement performs one clear action, and the multiline exception arguments are readable. Reading flow: The progression from state to validation to representation is natural, with minor distractions from import clutter and inconsistent spacing.