Sample

pyint-f5144ee0ee36-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines24

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8370–1; higher is more readable
Mi0.3180–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.560–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): 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.655.551−21.633
Source linesThe number of non-empty source lines.24+9.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.577−6.866

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.78.56+0.463
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.055+0.41
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.96+0.194
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.25+0.151
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.23.819−0.077
Indentation frequencyHow rapidly indentation changes from line to line.22+0.024

Intercept 0.07 + feature contributions = 1.633 (log-odds).
Score = sigmoid(1.633) = 0.837.

Score0.318
Score19
Run 1

The code is highly readable with clear structure: imports are organized, the class uses a clean attrs-based definition with frozen/slots configuration, and methods are logically separated. Nesting is minimal (one conditional inside __call__), and intent is obvious—a reusable numeric validator with a descriptive error message. Code length is concise without being cryptic; each attribute and method serves a clear purpose. Action granularity is good: one meaningful action per line within the conditional block, and the error construction is straightforward. Reading flow is natural, moving from imports to class definition to method implementations. Minor deductions: the conditional could arguably be inverted for an 'if not' guard, and the docstring in __call__ is slightly redundant, but these are trivial. Overall, it demonstrates strong readability practices.

Run 2

The code is generally readable with a clear structure: imports are organized, the class is decorated with attrs, and each method has a distinct purpose. The __call__ method is concise with minimal nesting and clear logic, although it could be flattened slightly. Action granularity is well-maintained with one logical action per line, and the reading flow is natural. The __repr__ method is succinct but slightly cryptic due to the 'x' placeholder. Minor improvements could include adding type hints and using a more descriptive variable name than 'x'. Overall, the code is maintainable and understandable.

Run 3

The code is highly readable with a clear, focused purpose. It uses a simple frozen/slotted attrs class to implement a numeric validator. Structure is logical: imports, class definition, attributes, core validation method, and repr. Nesting is minimal—just one conditional inside __call__. Intent is explicit: the class name, attribute names, and method names all communicate purpose. Code length is concise without sacrificing clarity. Action granularity is appropriate, with one logical operation per line (comparison, message construction, exception raising). Reading flow is natural: the validation logic moves linearly from input comparison to error message to exception. Minor deductions: the import list could be trimmed (operator, re, Pattern, contextmanager appear unused in the snippet), and the docstring in __call__ explains mechanics rather than the 'why', but neither harms overall readability significantly.

Run 1

Code Structure: The validator is logically organized into attributes, validation behavior, and representation, although several imports are unused in this snippet and spacing between imports and the class is missing. Nesting: Only one conditional level keeps the code easy to follow. Clarity of intent: Descriptive names and informative error messages make the bound comparison clear; the __call__ docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs one clear action, and message construction is separated from raising the exception. Reading flow: Attributes followed by __call__ and __repr__ provide a natural progression, with minor visual clutter from the imports.

Run 2

Code Structure: The small validator class logically groups configuration, validation, and representation, although several imports are unused in this snippet and spacing between imports and the class is missing. Nesting: A single conditional keeps control flow shallow. Clarity of intent: Descriptive field names and the error message make numeric-bound validation clear; the call-method docstring explains the class design rather than the method's behavior. Code length: The implementation is concise, with little unnecessary code beyond the unused imports. Action granularity: Each statement performs one action, and error-message construction is separated from raising the exception. Reading flow: Fields followed by validation and representation provide a natural progression, though the decorators and library-specific field declarations require some familiarity.

Run 3

Code Structure: Imports, class attributes, validation logic, and representation are logically organized, though missing blank lines around the class reduce visual separation. Nesting: A single conditional keeps the code shallow and easy to follow. Clarity of intent: The class name, comparison fields, and error message clearly communicate numeric-bound validation; however, the docstring explains the callable-class design rather than the method's behavior, and several imports are unused in this snippet. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs one clear action, including separate error-message construction and raising. Reading flow: The sequence from configuration fields to validation and representation is natural, although decorator-specific attribute behavior requires some familiarity with the library.