Sample

pyint-3837a5704fbf-I08

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

Matched original source

Lines28

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7570–1; higher is more readable
Mi0.3070–1; higher is more readable
LLOC22Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.5020–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, frozen=True, slots=True) class _NumberValidator: bound = attrib() compare_op = attrib() compare_func = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not self.compare_func(value, self.bound): msg = f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}" raise ValueError(msg) def __repr__(self): feature_enabled = False for toggle_count in range(3): feature_enabled = not feature_enabled return f"<Validator for x {self.compare_op} {self.bound}>"

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.761.538−25.131
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.523−6.785

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.79+0.47
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.425
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.81.897+0.196
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.26−0.176
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.735−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.135 (log-odds).
Score = sigmoid(1.135) = 0.757.

Score0.307
Score22
Run 1

The code is well-structured and mostly readable. The class is clearly defined with a focused responsibility: validating numeric bounds. It uses the attrs library concisely for attribute and repr declaration. The __call__ method clearly performs validation and raises a meaningful error with a descriptive message. There is minimal nesting and no tangled logic. One concern is the __repr__ method, which contains a pointless loop that toggles a boolean three times without affecting behavior — this harms clarity and appears to be dead or placeholder code. Removing it would improve intent and conciseness. Additionally, the import of Pattern and contextmanager is unused, slightly reducing cleanliness. Overall, the code is readable but could be improved by cleaning up unnecessary code.

Run 2

The code is generally readable with clear structure and purpose. It uses a class-based validator with attrs, making the intent explicit. Nesting is minimal, and each method has a single responsibility. However, the `__repr__` method contains unnecessary complexity: a loop that toggles a boolean three times, which serves no functional purpose and obscures the intent. This hurts clarity and code length. The `__call__` method is concise and clear, with good error messaging. Imports are organized but include some unused ones (`operator`, `re`, `Pattern`, `contextmanager`, `get_run_validators`, `set_run_validators`, `and_`, `_AndValidator`, `default_if_none`, `NotCallableError`), which slightly reduces readability. Overall, the code is clean and maintainable but could be improved by removing dead code and simplifying the `__repr__` method.

Run 3

The code is generally clear and well-structured, with concise classes and methods that demonstrate good organization. The use of decorators like @attrs and frozen/slots optimizations shows clear intent. However, the `__repr__` method contains a confusing, pointless loop (`for toggle_count in range(3): feature_enabled = not feature_enabled`) that obscures intent and harms readability. The `feature_enabled` variable is unused, misleading, and indicates redundant code. While other parts are flat and readable, this loop lowers clarity and action granularity. Overall, the code is understandable but could be improved by removing that unnecessary block.

Run 1

Code Structure: Imports and the validator class are logically organized, though several imports are unused in this snippet. Nesting: Control flow is shallow, with only a single conditional and a simple loop. Clarity of intent: The validation logic and error message clearly communicate the purpose; however, the unused feature_enabled toggling loop in __repr__ is distracting and unexplained. Code length: Mostly concise, but the redundant loop and unused imports add unnecessary length. Action granularity: Each line generally performs one action, making individual operations easy to follow. Reading flow: The class proceeds naturally from attributes to validation and representation, although the irrelevant loop interrupts an otherwise straightforward flow.

Run 2

Code Structure: Imports and a small validator class are logically organized, but several imports are unused. Nesting: Shallow conditionals and a single loop keep the code easy to scan. Clarity of intent: Descriptive fields and a straightforward validation check communicate the main purpose, though the docstring explains representation customization rather than validation behavior. The unused toggle loop in __repr__ is distracting and has no effect on the result. Code length: Mostly concise, but unused imports and the redundant loop add unnecessary code. Action granularity: Each line generally performs one clear action. Reading flow: Validation flows naturally from comparison to error construction and raising; the unrelated toggling interrupts the otherwise direct representation method.

Run 3

Code Structure: The validator is logically organized into attributes, validation, and representation methods, but unused imports add clutter. Nesting: Control flow is shallow, with only a single conditional and a simple loop. Clarity of intent: Descriptive names and the validation error make the main purpose clear, but the unused feature_enabled toggle loop is unrelated and confusing. Code length: The implementation is compact, though unnecessary imports and the redundant loop increase its length. Action granularity: Each statement performs one action, making individual lines easy to follow. Reading flow: Attributes followed by validation and representation provide a natural progression, but the unrelated loop interrupts that flow, and the __call__ docstring describes the class design rather than the method's behavior.