Sample

pyint-b94c689d8e7b-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines23

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8310–1; higher is more readable
Mi0.2610–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6210–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 _MinLengthValidator: min_length = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if len(value) < self.min_length: msg = f"Length of '{attr.name}' must be >= {self.min_length}: {len(value)}" raise ValueError(msg) def __repr__(self): return f"<min_len validator for {self.min_length}>"

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.578.587−19.093
Source linesThe number of non-empty source lines.23+9.2
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.597−6.895

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.917+0.598
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.46
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.24+0.187
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.22.784−0.091
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.86.958−0.018
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 1.592 (log-odds).
Score = sigmoid(1.592) = 0.831.

Score0.261
Score17
Run 1

The code is well-structured with clear separation of imports, class definition, and methods. It uses a frozen and slotted attrs class, which makes intent explicit and prevents runtime mutation. Nesting is minimal—only a single if-statements inside the __call__ method. The purpose is obvious from the class name and docstring. The __repr__ improves debugging. The only minor issue is that the __call__ method could have type hints for clarity, and the docstring is a bit redundant but acceptable. Overall, it is concise, readable, and follows idiomatic Python practices, earning a high readability score.

Run 2

The code is well-structured and readable. It has a clear purpose: defining a frozen validator class using attrs. The imports are organized, though only some are used in this snippet (likely part of a larger module). Nesting is shallow, with a single condition inside the __call__ method. Naming clearly conveys intent (_MinLengthValidator, min_length, value). The class is concise and avoids unnecessary verbosity. Action granularity is appropriate: the validation check, message formatting, and exception raising are each on separate lines. Reading flow is natural—imports, class definition, attributes, method, and repr follow a logical order. Minor deductions: the docstring is only a brief implementation note rather than a full explanation, and the __repr__ message could be slightly more descriptive. Overall, the code is highly readable and maintainable.

Run 3

The code demonstrates high readability. It is well-structured for its purpose as a validator class. Nesting is minimal, with a single conditional check inside the __call__ method. The intent is clear: enforce a minimum length constraint on a value. Code length is concise and appropriate, avoiding unnecessary verbosity. Action granularity is reasonable, with the length check and error message creation on separate lines for clarity. Reading flow is natural, from import statements to class definition and methods. The use of the @attrs decorator with frozen=True and slots=True shows modern Python practices. The docstring explaining why a callable class is used adds helpful context. Minor deductions could include the unusual import structure without blank lines between groups, but overall the code is clean, focused, and follows Python conventions well.

Run 1

Code Structure: The validator is logically organized into configuration, validation, and representation methods, though numerous unused imports add clutter. Nesting: A single conditional keeps the code flat and easy to follow. Clarity of intent: Descriptive names and a clear error message make the minimum-length check obvious; the docstring explains the callable-class design rather than the validation behavior. Code length: The implementation is concise, with little unnecessary code beyond the unused imports. Action granularity: Each line performs one clear action. Reading flow: The class reads naturally from its minimum-length field through validation to representation, although an additional blank line before the top-level class would improve formatting.

Run 2

Code Structure: Imports and a small validator class are logically organized, though several imports are unused in this snippet. Nesting: Minimal nesting, with only one conditional inside a method. Clarity of intent: The class name, min_length attribute, comparison, and descriptive error message clearly communicate minimum-length validation; the __call__ docstring explains the class design rather than the method's behavior. Code length: The implementation is concise with no unnecessary logic. Action granularity: Each statement performs a single clear action, and error-message construction is separated from raising the exception. Reading flow: The class progresses naturally from configuration to validation to representation. Minor formatting improvements, such as a blank line after imports, would improve readability.

Run 3

Code Structure: The validator is logically organized into configuration, validation, and representation methods, though numerous unused imports add clutter. Nesting: A single conditional keeps the code flat and easy to follow. Clarity of intent: Descriptive class and attribute names clearly communicate minimum-length validation; the __call__ docstring explains the class design rather than the method's behavior. Code length: The implementation is concise, with little unnecessary code beyond unused imports. Action granularity: Each statement performs a clear action, and separating message construction from raising the exception improves readability. Reading flow: The progression from the length constraint to validation and representation is natural, although additional spacing between imports and the class would improve visual separation.