Sample

pyint-10be0f3108f3-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines25

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.770–1; higher is more readable
Mi0.0740–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.5340–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.25+10
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.412−6.619

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

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
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.26+0.116
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.24.769−0.064
Indentation frequencyHow rapidly indentation changes from line to line.23+0.058

Intercept 0.07 + feature contributions = 1.211 (log-odds).
Score = sigmoid(1.211) = 0.77.

Score0.074
Score17
Run 1

The code is generally readable with clear intent, logical imports, and a simple class structure. It uses a callable class to validate instance types, which is well-documented. However, readability is slightly reduced by inconsistent formatting: the closing parenthesis in the raise statement is misaligned with extra spaces, and blank lines between imports and the class definition are missing. The method signature and error message are clear, but the trailing spaces in the raise call break visual flow. Overall, the structure is flat, concise per line, and the purpose is evident, but minor layout issues prevent a higher score.

Run 2

The code has a clear purpose and reasonably flat structure, but several readability issues reduce its score. The import block is logical, and the class definition is concise with one main method. However, the error message construction is unnecessarily long and wrapped awkwardly across multiple lines, with an oddly indented closing parenthesis. The function signature spans multiple lines without clear visual separation, and the docstring, while helpful, is minimal. The use of a callable class is justified and explained, which aids clarity. Nesting is minimal, and actions are mostly one per line. Overall, the code is understandable but could be improved with cleaner formatting, shorter error message lines, and more consistent indentation.

Run 3

The code is generally readable but has several issues. It uses clear naming and a single responsibility class, but it has an unnecessary import (`operator`, `re`), a malformed closing parenthesis, and a trailing comma that hurts clarity. The deep indentation in the `msg` assignment breaks the reading flow, and the error message construction feels overly compressed into one line, reducing clarity of intent. The code structure is mostly logical, but the presence of unused imports and formatting inconsistencies lowers its readability. Action granularity is mostly one action per line, but the long f-string and the oddly placed closing parenthesis violate this. Nesting is shallow, which is good, but the overall formatting could be cleaner. A score of 12 reflects the potential but also the visible carelessness in formatting and code hygiene.

Run 1

Code Structure: The validator class logically groups its state, validation behavior, and representation, although several unused imports add clutter. 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 type validation; the docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise, but unnecessary imports reduce focus. Action granularity: Statements generally perform one action per line, with error-message construction separated from raising the exception. Reading flow: The sequence is natural, but missing blank lines around the class and its members, the long message line, and the awkwardly positioned closing parenthesis detract from readability.

Run 2

Code Structure: The validator class logically groups its configuration, validation behavior, and representation, though imports and definitions lack separating blank lines. Nesting: A single conditional keeps the implementation shallow and easy to follow. Clarity of intent: Class and method names clearly convey type validation, and the error message is informative; the docstring explains the callable-class design rather than validation behavior. Code length: The implementation is concise, but several imports appear unused in the provided snippet. Action granularity: Statements generally perform one action each; the malformed-looking spacing around the final exception argument reduces visual clarity. Reading flow: Configuration, validation, and representation follow a natural order, but inconsistent whitespace and awkward formatting of the raise statement interrupt readability.

Run 3

Code Structure: The validator class logically groups its type attribute, validation behavior, and representation, though unused imports and missing blank lines add clutter. Nesting: Shallow nesting makes the control flow easy to follow. Clarity of intent: The class name, isinstance check, and descriptive error message clearly convey the purpose; the docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise, but unnecessary imports reduce focus. Action granularity: Statements generally perform one action each, and constructing the error message separately helps readability. Reading flow: Validation proceeds naturally from checking the value to raising an exception, but the long message line and awkward closing-parenthesis placement in the TypeError call interrupt the flow.