Sample

pyint-40c7a0dc7227-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines25

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8350–1; higher is more readable
Mi0.2370–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro14.330–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.5650–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 _SubclassOfValidator: type = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not issubclass(value, self.type): msg = f"'{attr.name}' must be a subclass of {self.type!r} (got {value!r})." raise TypeError( msg, attr, self.type, value, ) def __repr__(self): return f"<subclass_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.404−6.605

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.923+0.598
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.049+0.464
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.773−0.064
Indentation frequencyHow rapidly indentation changes from line to line.23+0.058
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.87−0.02

Intercept 0.07 + feature contributions = 1.621 (log-odds).
Score = sigmoid(1.621) = 0.835.

Score0.237
Score17
Run 1

The code has clear structure and logical organization with appropriate imports and a well-defined class using attrs. Naming is descriptive and the intent is mostly clear. However, there are several readability issues: the raise TypeError call is formatted with excessive whitespace, breaking the natural reading flow; the code mixes one-action-per-line with awkward multi-line formatting; and the __call__ method's docstring explains implementation rationale rather than usage. Nesting is flat, which is good, and the overall length is concise. The __repr__ is concise and clear. The main problems are formatting inconsistencies and lack of user-facing documentation.

Run 2

The code is generally readable but has some inconsistent formatting and a fragmented call structure. The class is concise and its purpose is clear: a validator that checks if a value is a subclass of a specified type. However, the `raise TypeError(...)` call spans multiple lines with awkward indentation and excessive whitespace, breaking reading flow and violating one-action-per-line clarity. The imports include unused ones (`operator`, `re`, `Pattern`, `default_if_none`, `NotCallableError`), adding unnecessary noise. The `__call__` docstring helps clarify intent, and the nesting is minimal. Overall, the structure is logical but formatting inconsistencies and unused imports detract from readability.

Run 3

The code is generally readable with clear intent and logical structure. It defines a single-purpose validator class using attrs, with a concise __call__ method. The nesting is minimal—only one level in the __call__ method—and each line performs one action. The error message is clear. However, readability is slightly reduced by the awkwardly formatted raise TypeError call, where arguments are spread across multiple lines with excessive indentation, disrupting reading flow. The import of re and Pattern is unused, adding minor noise. Overall, the code is well-organized and understandable, but those small formatting and cleanliness issues prevent a higher score.

Run 1

Code Structure: The validator class logically groups its configuration, validation behavior, and representation, but several unused imports add clutter. Nesting: A single conditional keeps nesting shallow. Clarity of intent: The class name, subclass check, and descriptive error message make the purpose clear; however, the __call__ docstring explains the implementation choice rather than validation behavior, and abbreviated parameter names are less explicit. Code length: The class is concise, though unnecessary imports increase overall length. Action granularity: Most lines perform one action, but the TypeError call awkwardly places multiple arguments on its opening line. Reading flow: Validation proceeds naturally from checking the value to constructing and raising an error. Inconsistent spacing in the exception call and limited blank lines around imports, the class, and methods interrupt an otherwise straightforward flow.

Run 2

Code Structure: The validator class logically groups validation and representation, although several unused imports add clutter. Nesting: Shallow nesting makes control flow easy to follow. Clarity of intent: The class name, subclass check, and descriptive error message clearly communicate the purpose; the docstring explains the callable-class choice rather than the validation behavior. Code length: The implementation is concise, but unnecessary imports reduce economy. Action granularity: Most lines perform one action, though the malformed-looking spacing and mixed argument placement in the TypeError call impair scanning. Reading flow: Execution proceeds naturally from checking to raising an error, followed by representation, but inconsistent whitespace and insufficient separation between imports, the class, and methods weaken readability.

Run 3

Code Structure: The validator class is logically organized, but numerous unused imports add clutter. Nesting: Shallow nesting makes the validation path easy to follow. Clarity of intent: The class name, subclass check, and descriptive error message clearly convey its purpose; the docstring explains the callable-class design rather than the validation behavior. Code length: The implementation is concise, though the imports are excessive for this snippet. Action granularity: Most lines perform one action, but the awkwardly formatted TypeError arguments reduce scanability. Reading flow: Execution flows naturally from checking the value to raising an error, followed by a readable representation method; inconsistent spacing and limited separation between imports, class attributes, and methods weaken presentation.