Sample

pyint-4338fa678893-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines28

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.7770–1; higher is more readable
Mi0.0760–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.5380–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 _InstanceOfValidator: type = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not isinstance(value, self.type): msg = f"'{attr.name}' must be {self.type!r} (got {value!r} that is a {value.__class__!r})." raise TypeError( msg, attr, self.type, value, ) def __repr__(self): return f"<instance_of validator for type {self.type!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.635.312−20.965
Source linesThe number of non-empty source lines.28+11.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.417−6.626

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.103+0.857
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.103−0.697
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.048+0.472
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.26+0.162
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.27.779−0.022
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.29+0.01

Intercept 0.07 + feature contributions = 1.25 (log-odds).
Score = sigmoid(1.25) = 0.777.

Score0.076
Score17
Run 1

The code is highly readable with a clear, single-purpose class. It has a flat structure with minimal nesting—only a single conditional inside the __call__ method. The intent is explicit: a validator that checks if a value is an instance of a specified type, raising a descriptive TypeError otherwise. The code is concise, with no unnecessary lines. Action granularity is appropriate; each line performs one logical step, such as constructing the error message or raising the exception. Reading flow is natural, following a top-down progression from imports to class definition and methods. The use of attrs for class definition and f-strings for error messages enhances clarity. Minor deductions only because the type annotation (type = attrib()) could be more explicit, and the error message construction is slightly verbose, but overall it's clean and maintainable.

Run 2

The code is generally readable with clear intent and logical structure. It defines a validator class using attrs, with a straightforward __call__ method and a repr method. The code is flat with minimal nesting, one action per line, and a natural reading flow. However, it could be improved by simplifying the error message construction, which is spread over multiple lines and contains redundant information, making it slightly verbose. The import block includes unused imports (_AndValidator, and_, default_if_none, etc.), which adds clutter and reduces clarity. The use of a callable class is justified, but the __call__ method could be more concise. Overall, the code is readable but not exemplary due to minor verbosity and unnecessary imports.

Run 3

The code is a concise, well-structured validator class using the attrs library. Imports are minimal and clear, with unused ones (operator, re, Pattern, contextmanager) all imported—this slightly affects clarity. The class is logically organized with a clear __call__ method that performs a single validation action, and the error message is explicit. Nesting is flat, with only one conditional check. Action granularity is appropriate: each line performs a distinct action, improving readability. Reading flow is natural—validation logic, error raising, and __repr__ definition are separated cleanly. The docstring succinctly explains the design choice of using a callable class. Minor drawbacks: the function could be broken into smaller helpers for complex type-checking scenarios, and the unused imports could confuse maintainers. Overall, highly readable and maintainable.

Run 1

Code Structure: The validator class logically separates its field, validation behavior, and representation, though several imports are unused in the snippet. Nesting: A single conditional keeps control flow shallow. Clarity of intent: Descriptive names and the explicit isinstance check clearly convey type validation; the docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise, although the multiline exception arguments add minor verbosity. Action granularity: Each statement performs one clear action, with message construction separated from raising the exception. Reading flow: Imports, class declaration, validation, and representation follow a natural sequence. The long error-message line and framework-specific decorators slightly reduce immediate readability.

Run 2

Code Structure: Imports, class configuration, validation logic, and representation are logically organized, though several imports are unused in this snippet. Nesting: A single conditional keeps the code shallow and easy to follow. Clarity of intent: The class name, isinstance check, and descriptive error message clearly communicate the validation purpose; the generic type attribute and framework-specific decorators require some context. Code length: The implementation is concise, although the multiline exception construction adds modest visual overhead. Action granularity: Each statement performs one clear action, with message construction separated from raising the exception. Reading flow: The code progresses naturally from configuration to validation and representation. The docstring explains the callable-class design rather than the method's validation behavior, slightly reducing clarity.

Run 3

Code Structure: Imports and a compact validator class are logically organized, although several imports are unused in this snippet. Nesting: Only one conditional appears, keeping control flow shallow. Clarity of intent: The class name, isinstance check, descriptive error message, and custom representation clearly communicate type validation; abbreviated parameters and the decorator's implicit behavior require some familiarity. Code length: Concise overall, though the multiline exception construction is slightly verbose. Action granularity: Each statement performs one clear action, with message construction separated from raising the exception. Reading flow: The code progresses naturally from configuration to validation and representation. The docstring explains the callable-class design rather than the method's validation behavior, which slightly weakens local documentation.