Sample

pyint-7031081ab055-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines32

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8160–1; higher is more readable
Mi0.1580–1; higher is more readable
LLOC21Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.4470–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): 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): total_score = 240 number_of_scores = 3 average_score = total_score / number_of_scores 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.734.944−24.253
Source linesThe number of non-empty source lines.32+12.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.38−6.569

Intercept 8.87 + feature contributions = -9.153 (log-odds).
Score = sigmoid(-9.153) = 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.048+0.472
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+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.95.879−0.396
Indentation frequencyHow rapidly indentation changes from line to line.30+0.301
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.33−0.132
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.31.784+0.034

Intercept 0.07 + feature contributions = 1.492 (log-odds).
Score = sigmoid(1.492) = 0.816.

Score0.158
Score21
Run 1

The code is generally well-structured and readable. It uses a frozen attrs class with clear attributes, has a logical __call__ method with a clear validation purpose, and includes helpful docstrings and repr customization. Imports are organized but include some unused ones (operator, contextmanager, Pattern, etc.), which slightly reduces clarity. The nesting level is shallow and flow is natural. However, the __repr__ method contains unrelated dummy code (total_score, number_of_scores, average_score) that serves no purpose and misleads the reader, breaking the clarity of intent. Aside from that artifact, the code is concise and each action is clearly delineated.

Run 2

The code is generally clear and well-structured. It uses a frozen/slotted attrs class for a validator, implements `__call__` with a clear error message, and includes a custom `__repr__`. The imports are mostly relevant but `operator`, `re`, `contextmanager`, `get_run_validators`, `set_run_validators`, `and_`, `_AndValidator`, `attrib`, `default_if_none`, and `NotCallableError` appear unused, which hurts readability. Nesting is minimal and the flow is logical. However, the inclusion of irrelevant variables (`total_score`, `number_of_scores`, `average_score`) inside `__repr__` is confusing and seems accidental. These extra imports and dead variables add unnecessary length and ambiguity.

Run 3

The code is mostly clear with logical structure and flat nesting. The validator class is concise and the intent is easy to understand. However, there is a confusing block of unrelated arithmetic (total_score, number_of_scores, average_score) inside __repr__, which is ambiguous and breaks reading flow. Action granularity is generally one action per line. The import of `Pattern` and unused imports like `operator`, `re`, and `contextmanager` reduce readability. Overall, it is readable but slightly marred by the odd dead code in __repr__ and unnecessary imports.

Run 1

Code structure is logical: a small validator class separates validation from representation, though several imports are unused. Nesting is shallow, with only one conditional. Intent is mostly clear from class and attribute names and the descriptive error message, but the __call__ docstring explains representation rather than validation. Code length is modest, although unused score calculations in __repr__ and unused imports add unnecessary clutter. Action granularity is good, with one operation per line and a clearly formatted exception. Reading flow is natural overall, but the unrelated arithmetic in __repr__ interrupts it and suggests leftover code.

Run 2

Code Structure: Imports and validator methods are logically organized, but several unused imports and unrelated score calculations in __repr__ add clutter. Nesting: The code is shallow, with only one conditional inside __call__. Clarity of intent: Class and attribute names, the regex check, and the error message clearly communicate validation behavior; the score calculations have no apparent purpose. Code length: Mostly concise, though unused imports, dead calculations, and the expanded exception call introduce unnecessary length. Action granularity: Each statement performs one action, making individual steps easy to follow. Reading flow: The progression from attributes to validation to representation is natural, but the irrelevant arithmetic interrupts the final method.

Run 3

Code Structure: Imports and validator methods are logically organized, but several imports are unused and unrelated score calculations clutter __repr__. Nesting: Minimal nesting makes control flow easy to follow. Clarity of intent: Class and method names clearly indicate regex validation, and the error message is informative; however, the __call__ docstring explains the class design rather than the method's behavior, and the unused calculations are misleading. Code length: Mostly concise, though unused imports, dead calculations, and an expanded exception call add unnecessary length. Action granularity: Each statement performs one action, making individual steps easy to scan. Reading flow: Validation proceeds naturally from checking the value to raising an error, but the unrelated arithmetic interrupts the representation method.