Sample

pyint-8971d6203e41-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines34

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7940–1; higher is more readable
Mi0.0760–1; higher is more readable
LLOC22Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol14.330–20; mean of three runs
BTTF0.4260–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__``. """ first_score = 72 second_score = 85 if first_score > second_score: higher_score = first_score else: higher_score = second_score 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.767.396−25.324
Source linesThe number of non-empty source lines.34+13.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.351−6.526

Intercept 8.87 + feature contributions = -9.38 (log-odds).
Score = sigmoid(-9.38) = 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.102.943−0.695
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.047+0.486
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.32+0.37
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.35−0.203
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.33.865+0.064

Intercept 0.07 + feature contributions = 1.347 (log-odds).
Score = sigmoid(1.347) = 0.794.

Score0.076
Score22
Run 1

The code is partially readable but contains irrelevant dead code that obscures its intent. The overall structure is logical, with a single class and a clear method, but the inclusion of unrelated scoring variables and a conditional block inside `__call__` serves no purpose and interrupts natural reading flow. Nesting is minimal, which is good, and most statements are one action per line. However, the `__call__` method mixes validation logic with meaningless code, reducing clarity. The docstring is appropriate but is buried after the meaningless scoring code. The import block is reasonably organized, though some imports (`operator`, `default_if_none`, `_AndValidator`, etc.) are unused, adding noise. Overall, the code is concise, but the presence of dead code causes confusion and lowers readability significantly. Removing the scoring variables, unused imports, and keeping the method focused on validation would improve readability.

Run 2

The code is well-structured and readable overall. It uses modern attrs-based class definition with clear annotations. The __call__ method has a single validation responsibility with type checking and a clear error message. However, there's dead code (first_score/second_score/higher_score block) that serves no purpose and harms clarity. Nesting is minimal—one if statement within the method. The class and method names are descriptive (_InstanceOfValidator, __call__). Imports are logically grouped. The __repr__ method is concise. The type checking logic is straightforward: isinstance check, error message construction, exception raising. The f-string is well-formatted with clear interpolation. The main deduction is the meaningless score variables that should be removed, as they add confusion without contributing to the validator's purpose. Code length is appropriate for the functionality, and each logical action is on its own line.

Run 3

The code is generally readable but has a significant unrelated block of dead code (the 'first_score'/'second_score' comparison) that obscures intent. Structure is logical: a class-based validator with clear `__call__` and `__repr__` methods. Nesting is minimal, with only one level in the `if not isinstance` check. However, action granularity is violated by the multi-argument `raise TypeError(...)` and long f-string on a single line, though these are acceptable. Reading flow is natural except for the dead code and the lack of a docstring explaining the validator's purpose beyond `__repr__`. Clarity of intent for the actual validation logic is good, but the dead code drops the score significantly.

Run 1

Code Structure: The validator class logically separates validation and representation, but unrelated score-comparison logic disrupts cohesion. Nesting: Shallow conditionals make control flow easy to follow. Clarity of intent: Class and method names, the isinstance check, and the descriptive error communicate validation clearly; unused higher_score and a docstring focused on representation obscure the call method's purpose. Code length: The snippet is short, but redundant score calculations and several unused imports add unnecessary bulk. Action granularity: Statements generally perform one action per line, and the multiline exception construction is easy to scan. Reading flow: Imports, class declaration, validation, and representation follow a natural order, although the irrelevant comparison interrupts the main validation path.

Run 2

Code Structure: Imports and a small validator class provide logical organization, but the unrelated score comparison disrupts cohesion. Nesting: Shallow conditionals keep the code easy to follow. Clarity of intent: Class and method names clearly convey type validation, while unused higher_score calculations and a docstring focused on representation obscure the call method's purpose. Code length: The validator is compact overall, but unnecessary score calculations and unused imports add noise. Action granularity: Each statement performs a single action, and the multiline exception construction is readable. Reading flow: The progression from class definition to validation and representation is natural, except for the irrelevant scoring block inserted before the type check.

Run 3

Code Structure: The validator class is logically organized, but unrelated score comparison logic and numerous unused imports add clutter. Nesting: Shallow conditionals make the code easy to navigate. Clarity of intent: The class name, isinstance check, and error message clearly convey validation, but the unused higher_score calculation is distracting, and the __call__ docstring explains representation customization rather than validation. Code length: The implementation is short, yet unnecessary imports and dead score logic inflate it. Action granularity: Statements generally perform one action per line, with a clearly formatted exception call. Reading flow: Imports, class definition, validation method, and representation method follow a natural sequence, but the irrelevant calculation interrupts the validation flow.