Sample

pyint-a2aaeb8d4de4-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.260–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6170–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 _MaxLengthValidator: max_length = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if len(value) > self.max_length: msg = f"Length of '{attr.name}' must be <= {self.max_length}: {len(value)}" raise ValueError(msg) def __repr__(self): return f"<max_len validator for {self.max_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.609−6.914

Intercept 8.87 + feature contributions = -7.937 (log-odds).
Score = sigmoid(-7.937) = 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.26
Score17
Run 1

The code is well-structured and highly readable. It imports only what is needed, defines a single focused class with a clear purpose, and keeps nesting minimal (one level inside __call__). The validation logic is straightforward: check length, raise error with a clear message. The custom __repr__ method enhances debugging. Naming is descriptive, and the docstring clarifies the design choice. The class is concise without unnecessary verbosity, and each logical action is separated naturally. Minor deductions: some imports like operator, re, and Pattern appear unused, and the overall module lacks context, but within the given snippet, readability is strong.

Run 2

The code is highly readable with a clear, focused structure. It uses a single class to encapsulate validation logic, keeping the overall design simple and logical. Nesting is minimal, with only one conditional inside the __call__ method, promoting flat code. The intent of the class is clear from its name and docstring. The method bodies are concise, each performing one logical action. Action granularity is appropriate—each line in __call__ does one distinct thing. The reading flow is natural, with functionality grouped neatly and imports organized. The main minor deduction is the slightly vague docstring about changing the repr, which could be more explanatory.

Run 3

The code is generally clear and well-structured. It uses a frozen, slotted attrs class for a validator, which is logical. The __call__ method is flat, with only one level of nesting inside the conditional. Intent is evident: enforce a maximum length. The __repr__ method aids debugging. However, some imports appear unused (e.g., default_if_none, Pattern) or indirectly related (e.g., get_run_validators, and_), which could cause confusion. The docstring is brief but focused on the repr rationale. Overall, the class is concise and readable, though cleaning up imports would improve clarity.

Run 1

Code Structure: The validator class cleanly groups its configuration, validation logic, and representation, though several imports are unused in this snippet. 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, clearly convey maximum-length validation; the __call__ docstring explains representation customization rather than the method's validation purpose. Code length: The implementation is concise, with little unnecessary code beyond the unused imports. Action granularity: Each statement performs one clear action. Reading flow: Configuration, validation, and representation appear in a natural order, with appropriate spacing. Minor improvements would include removing unused imports and making the docstring more directly describe validation.

Run 2

Code Structure: The validator class logically groups its configuration, validation behavior, and representation, 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 maximum-length constraint obvious; the __call__ docstring explains the callable-class design rather than the method's validation behavior. Code length: The implementation is concise, although len(value) is repeated and imports exceed what this snippet needs. Action granularity: Each statement performs one clear action. Reading flow: Configuration, validation, and representation appear in a natural order, with readable spacing and straightforward control flow.

Run 3

Code Structure: The validator is logically organized into configuration, validation, and representation methods, though numerous unused imports clutter the snippet. Nesting: A single conditional keeps control flow flat and easy to follow. Clarity of intent: Descriptive class and attribute names, a straightforward length check, and a helpful error message make the purpose clear; the callable-method docstring explains the design choice rather than its validation behavior. Code length: The implementation is concise, with little unnecessary code beyond the imports. Action granularity: Each line performs one clear action. Reading flow: The class reads naturally from its length limit to enforcement and display, although attrs-specific conventions may require background knowledge.