Sample

pyint-c9b9bbb00195-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines29

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8590–1; higher is more readable
Mi0.3340–1; higher is more readable
LLOC16Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6120–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=False, unsafe_hash=True) class _IsCallableValidator: def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not callable(value): message = ( "'{name}' must be callable " "(got {value!r} that is a {actual!r})." ) raise NotCallableError( msg=message.format( name=attr.name, value=value, actual=value.__class__ ), value=value, ) def __repr__(self): return "<is_callable validator>"

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.711.107−23.467
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.279−6.419

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

Feature contributions

FeatureValueContribution
(log-odds)
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.70.967+0.659
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.052+0.432
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 (horizontal)How rapidly the visual pattern of comment characters changes from left to right.54.967+0.082
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.889−0.006

Intercept 0.07 + feature contributions = 1.807 (log-odds).
Score = sigmoid(1.807) = 0.859.

Score0.334
Score16
Run 1

The code is well-structured and highly readable. Imports are organized, the class uses a decorator for concise setup, and the `__call__` method has a clear purpose with a helpful docstring. The error message construction is logical and the validation logic is straightforward. There is one action per line and minimal nesting. The `__repr__` method is simple and explicit. Minor points deducted because the multi-line message string with `.format()` is slightly verbose, and the `msg=` keyword in `NotCallableError` adds a small amount of noise, but overall the code is clean, intent-revealing, and easy to follow.

Run 2

The code is generally well-structured and readable. It has a clear purpose—defining a validator class—and uses a single class with a single method, keeping the logic flat and avoiding deep nesting. The docstring clarifies intent, and the error message is explicit. Action granularity is good; the class and method each perform focused tasks. However, the import block includes several unused imports (operator, re, Pattern, contextmanager, get_run_validators, set_run_validators, and_, attrib, attrs, default_if_none). These extraneous imports add noise, increasing apparent length without contributing to the validator’s functionality. The score reflects strong readability with a minor penalty for unused imports and slight verbosity.

Run 3

The code is well-structured with clear imports, a focused class definition, and a single method that performs one validation task. Nesting is minimal, and the logic is straightforward. The intent is clear: validate that a value is callable and raise a descriptive error otherwise. The error message construction is slightly verbose but aids clarity. One minor readability concern is the inline comment within the __call__ method, which could be placed as a docstring or module-level note. Overall, the code is concise and maintains a natural reading flow.

Run 1

Code Structure: Imports and a focused validator class are logically organized, although several imports are unused in this snippet. Nesting: A single conditional keeps control flow shallow; nested formatting in the exception construction remains manageable. Clarity of intent: The class name, callable check, descriptive error message, and custom representation clearly communicate the purpose. The docstring explains the class-based design, though decorator options require library familiarity. Code length: The implementation is concise, with slightly verbose message construction and unnecessary imports. Action granularity: Each statement performs one distinct action, and multiline formatting improves readability. Reading flow: The code proceeds naturally from validation to failure reporting and then representation; an additional blank line between imports and the class would improve visual separation.

Run 2

Code Structure: The validator is logically organized into a callable validation method and a separate representation method, though several imports appear unused in this snippet. Nesting: A single conditional keeps control flow shallow; multiline exception construction remains easy to follow. Clarity of intent: The class name, callable check, and descriptive error message clearly communicate the purpose. The docstring explains the callable-class design rather than the method's validation behavior. Code length: The implementation is concise, with modest overhead from unused imports and message formatting. Action granularity: Each statement performs one clear action; multiline arguments improve readability rather than combining unrelated operations. Reading flow: Execution proceeds naturally from checking the value to constructing and raising an informative exception. Additional spacing between imports and the class would improve visual separation.

Run 3

Code Structure: The validator is logically organized into validation and representation methods, though several unused imports add clutter. Nesting: Control flow is shallow, with a single conditional; nested formatting calls remain easy to follow. Clarity of intent: Descriptive class and method names, a straightforward callable check, and a detailed exception clearly communicate the purpose. The docstring explains the callable-class design rather than the method's validation behavior. Code length: The implementation is concise, although imports unrelated to this snippet reduce focus. Action granularity: Each statement performs a distinct action, and multiline formatting keeps the exception construction readable. Reading flow: The code proceeds naturally from checking the value to constructing and raising an error, followed by the custom representation. Additional spacing between imports and the class would improve visual separation.