Sample

pyint-b95e0b3573ac-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines29

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8080–1; higher is more readable
Mi0.1650–1; higher is more readable
LLOC18Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5610–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): 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.652.329−21.527
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.388−6.582

Intercept 8.87 + feature contributions = -7.639 (log-odds).
Score = sigmoid(-7.639) = 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.05+0.459
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.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.763−0.008

Intercept 0.07 + feature contributions = 1.434 (log-odds).
Score = sigmoid(1.434) = 0.808.

Score0.165
Score18
Run 1

The code is well-structured and readable. It follows a clear logical organization, with a focused class definition and minimal nesting. The intent is immediately understandable: a validator that checks if a value matches a regular expression. Variable names are descriptive ('pattern', 'match_func', 'inst', 'attr', 'value'). The error message is informative and includes relevant context. The __repr__ method clearly summarizes the validator. The only minor deductions are for slight verbosity in the docstring (attribution is implicit) and the somewhat compressed conditional raise, although it remains clear. Overall, the code is concise, easy to follow, and maintains a natural reading flow.

Run 2

The code is generally well-structured and readable. It uses clear naming (_MatchesReValidator), modern Python features (frozen slots attrs class), and separates validation logic from representation. Nesting is shallow—only one if statement inside __call__. Intent is evident: validate a value against a regex pattern. Action granularity is appropriate, with each logical step on its own line. The f-string error message is somewhat long but still clear. Minor deductions: the docstring is helpful but could state the purpose more directly, and the import block is partially unused (operator, re, Pattern, contextmanager, get_run_validators, set_run_validators, _AndValidator, and_, default_if_none, NotCallableError are not referenced in this snippet), which adds visual noise. Overall, the code is concise, readable, and logically organized.

Run 3

The code is generally well-structured and readable. It uses clear naming conventions (_MatchesReValidator), leverages attrs for concise class definition, and has a flat structure with minimal nesting. The __call__ method has a clear purpose: validate a value against a regex pattern and raise a descriptive error if it fails. The error message construction is readable, and the use of f-strings enhances clarity. The class also includes a custom __repr__ for better debugging output, which improves maintainability. However, a few minor drawbacks affect readability: the match_func attribute is slightly ambiguous without context, and importing attributes like pattern and match_func from attrs could confuse developers unfamiliar with the library. Additionally, the __call__ method performs multiple actions (checking, formatting, raising) within a single conditional block, though it remains manageable. Overall, the code is concise and purposeful but could benefit from a short comment explaining match_func's role.

Run 1

Code Structure: The validator is logically organized into attributes, validation behavior, and representation, although several imports are unused in this snippet. Nesting: A single conditional keeps control flow shallow. Clarity of intent: Descriptive class and attribute names, together with a specific error message, make regex validation clear; the __call__ docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise, though the multiline exception construction is slightly verbose. Action granularity: Statements generally perform one action per line, with message construction separated from raising the exception. Reading flow: Imports, class attributes, and methods follow a natural order; a blank line separating standard-library and relative imports would improve presentation.

Run 2

Code Structure: Imports and a compact validator class provide clear organization, though several unused imports add clutter. Nesting: Only one conditional appears inside a method, keeping nesting shallow. Clarity of intent: Descriptive class and field names, a helpful docstring, and an informative error message make the validation purpose clear; the attrs-based field declarations require some library familiarity. Code length: The implementation is concise, although the multiline exception construction is slightly verbose. Action granularity: Each statement performs a single clear action. Reading flow: Fields, validation behavior, and representation follow a natural sequence, with consistent formatting; additional spacing between imports and the class would improve visual separation.

Run 3

Code Structure: The validator class is logically organized, with attributes, validation logic, and representation clearly separated; several unused imports add clutter. Nesting: A single conditional keeps the code flat and easy to follow. Clarity of intent: Descriptive class and attribute names, plus an informative error message, make the purpose clear, although the __call__ docstring explains the class design rather than the method's behavior. Code length: The implementation is concise, though the multiline exception construction is somewhat verbose. Action granularity: Each statement performs one clear action, with error-message construction separated from raising the exception. Reading flow: The progression from configuration to validation to representation is natural; additional spacing between imports and the class would improve visual separation.