Sample

pyint-4aa4a313ba34-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines21

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.7110–1; higher is more readable
Mi0.5080–1; higher is more readable
LLOC16Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6360–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, slots=True, unsafe_hash=True) class _OptionalValidator: validator = attrib() def __call__(self, inst, attr, value): if value is None: return self.validator(inst, attr, value) def __repr__(self): return f"<optional validator for {self.validator!r} or None>"

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.546.833−18.045
Source linesThe number of non-empty source lines.21+8.4
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.502−6.753

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
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.69+0.743
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.059+0.364
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.22+0.257
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.20.886−0.118
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 0.899 (log-odds).
Score = sigmoid(0.899) = 0.711.

Score0.508
Score16
Run 1

The code is well-structured with clear logical organization: imports are grouped (standard library, typing, then project-specific), and the class uses the attrs decorator idiomatically. Nesting is minimal—only one level of indentation inside the method, with an early return for the None case that improves readability. Intent is clear: this is a validator wrapper that skips validation for None values and delegates otherwise. The __repr__ method is concise and informative. Code length is appropriate; every line serves a purpose. Action granularity is good—each statement is a single logical action. The early return avoids an else block, making the flow natural and easy to follow. Minor deductions: the `_OptionalValidator` name is slightly redundant with the module context, and `self.validator(inst, attr, value)` relies on background knowledge of attrs validator signatures, but this is idiomatic and acceptable in the attrs ecosystem.

Run 2

The code is well-structured and readable. It imports are organized logically, and the class definition is clear and concise. The decorator @attrs is used effectively to reduce boilerplate. Nesting is minimal—only one level in the __call__ method. The intent is clear: the class wraps another validator to allow None values. Action granularity is good, with one main action per line in the __call__ method. The reading flow is natural: imports first, then class definition, followed by methods in a logical order. Minor deductions: the __repr__ method uses an f-string that could be slightly clearer with a named variable, and the __call__ method could benefit from a brief docstring explaining behavior. However, overall it is concise and purpose-driven.

Run 3

The code is well-structured and readable. It has a clear purpose: defining an optional validator wrapper. Imports are organized, though some unused imports (operator, re, Pattern, get_run_validators, etc.) slightly reduce clarity. The class uses the attrs decorator cleanly, and the __call__ method has simple, flat logic with one action per logical block. The early return for None improves readability by avoiding nesting. The __repr__ method is concise and informative. Minor deductions: unused imports and the lack of a docstring explaining the class's role or edge cases. Overall, the code is easy to follow, with good naming and minimal complexity.

Run 1

Code Structure: The small class cleanly separates validation behavior from representation, though several imports are unused in this snippet. Nesting: An early return keeps control flow flat and easy to follow. Clarity of intent: The class name, validator attribute, and explicit None check clearly communicate optional validation. The attrs decorator requires some library familiarity. Code length: The implementation is concise, with no unnecessary logic; unused imports add minor clutter. Action granularity: Each statement performs a single clear action. Reading flow: Imports, class definition, callable behavior, and representation follow a natural order, supported by sensible spacing.

Run 2

Code Structure: The class is logically organized, separating initialization metadata, validation behavior, and representation. Nesting: Minimal nesting and an early return keep control flow flat. Clarity of intent: The class name and methods clearly express optional validation, although abbreviated parameters and framework-specific decorators require some familiarity. Code length: The implementation is concise, but numerous unused imports add clutter to this snippet. Action granularity: Each statement performs a single action. Reading flow: Consistent spacing and straightforward method ordering make the code easy to follow.

Run 3

Code Structure: The class is logically organized, with its field, validation behavior, and representation clearly separated. Nesting: A single conditional and early return keep control flow flat. Clarity of intent: The class name, straightforward None check, and descriptive representation clearly communicate optional validation; framework-specific decorators and abbreviated parameters require some familiarity. Code length: The implementation is concise, although several imports are unused in the shown snippet and add clutter. Action granularity: Each statement performs one action, with no compressed or compound operations. Reading flow: Execution reads naturally from the None guard to delegation, and whitespace separates responsibilities effectively.