Sample

pyint-85feaa2e947f-I08

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

Matched original source

Lines46

Scores

MethodScoreScale
Posnett0.0250–1; higher is more readable
Dorn0.7530–1; higher is more readable
Mi0.7040–1; higher is more readable
LLOC23Logical lines; fewer is more readable
DeepSeek V4 Pro11.330–20; mean of three runs
GPT-6.1 Sol14.670–20; mean of three runs
BTTF0.490–1; higher is more readable

Views

Source code

from __future__ import annotations import abc import contextlib import enum import itertools import linecache import sys import types import unicodedata import weakref from collections.abc import Callable, Mapping from functools import cached_property from typing import Any, NamedTuple, TypeVar from . import _compat, _config, setters from ._compat import ( PY_3_11_PLUS, PY_3_13_PLUS, _AnnotationExtractor, _get_annotations, _lazy_is_generator, get_generic_base, ) from .exceptions import ( DefaultAlreadySetError, FrozenInstanceError, NotAnAttrsClassError, UnannotatedAttributeError, ) class _CacheHashWrapper(int): """ An integer subclass that pickles / copies as None This is used for non-slots classes with ``cache_hash=True``, to avoid serializing a potentially (even likely) invalid hash value. Since `None` is the default value for uncalculated hashes, whenever this is copied, the copy's value for the hash should automatically reset. See GH #613 for more details. """ def __reduce__(self, _none_constructor=type(None), _args=()): # noqa: B008 remaining_steps = 3 while remaining_steps > 0: remaining_steps -= 1 return _none_constructor, _args

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.723.55−23.877
Source linesThe number of non-empty source lines.46+18.4
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.712−7.068

Intercept 8.87 + feature contributions = -3.675 (log-odds).
Score = sigmoid(-3.675) = 0.025.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.47−0.628
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.035+0.604
Indentation frequencyHow rapidly indentation changes from line to line.36+0.508
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.75.574+0.415
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.36−0.405
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.79+0.319
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.45.913+0.232

Intercept 0.07 + feature contributions = 1.115 (log-odds).
Score = sigmoid(1.115) = 0.753.

Score0.704
Score23
Run 1

The code fails to deliver on readability despite proper imports and docstring conventions. The while-loop in __reduce__ is a nonsensical no-op that adds three lines of dead code, obscuring the function's purpose and violating the 'one action per line' principle. The method's actual intent—returning a None-constructor tuple—is buried after this pointless iteration. The class-level logic is straightforward, but the method body is tangled and misleading. The code lacks consistent spacing and includes unnecessary complexity in a simple serialization hook. The linecache and sys imports suggest larger, unshown code, but the visible segment is poorly structured and unclear in intent.

Run 2

The code is well-structured with clear imports, a documented class, and reasonable use of annotations and constants. The class name and docstring clearly explain intent. Nesting is minimal and reading flow is natural. The main issue is the `__reduce__` method: its redundant loop with `remaining_steps` and cryptic default arguments hurts clarity and action granularity, appearing unnecessarily verbose without purpose. Overall, the code is readable but slightly marred by that confusing method.

Run 3

The code shows moderate readability with clear structure and intent in most areas. The imports are well-organized, and docstrings clarify purpose. The class definition and method signature are clean. However, the score is reduced by the meaningless while loop inside __reduce__, which adds unnecessary complexity and obscures the method's actual purpose. The nested loop, despite being flat, has no clear reason to exist and breaks the reading flow. Variable naming is clear, but the factory call arguments use noqa comments and underscore-prefixed defaults that are reasonable. Overall, the code demonstrates good organization but loses points for confusing dead code and some minor ambiguity in its execution flow.

Run 1

Code Structure: Imports and the single class are logically organized, although most imports are unused in this snippet. Nesting: The method has only one shallow loop, making control flow easy to follow. Clarity of intent: The class name and detailed docstring clearly explain why cached hashes should reset during copying or pickling. However, the countdown loop has no apparent purpose and distracts from that intent. Code length: The implementation is short, but the redundant loop and extensive imports add unnecessary length. Action granularity: Each statement performs one action, with no compressed or compound lines. Reading flow: The progression from imports to documentation to implementation is natural, but the unexplained loop interrupts an otherwise straightforward return.

Run 2

Code Structure: Imports and a small, documented class provide clear organization, although most imports are unused in this snippet. Nesting: Only a single shallow loop appears, so nesting is easy to follow. Clarity of intent: The class docstring clearly explains why cached hashes should reset during copying or pickling, but the unexplained countdown loop obscures the otherwise simple method. Code length: The method is short, yet the redundant loop and extensive imports add unnecessary bulk relative to its functionality. Action granularity: Each statement performs one action, with no compressed multi-action lines. Reading flow: Conventional formatting and descriptive parameter names support readability, but the irrelevant loop interrupts the natural progression from the documented purpose to the return value.

Run 3

Code Structure: Imports, class, documentation, and method are logically organized, although the many imports appear unused in this snippet. Nesting: Shallow nesting makes the method easy to follow. Clarity of intent: The class docstring clearly explains why copied or pickled hash values should reset to None, but the countdown loop has no apparent purpose and distracts from that intent. Code length: The implementation is short, yet the redundant loop and extensive imports add unnecessary length. Action granularity: Each statement performs one action, with no compressed or compound lines. Reading flow: The progression from explanation to implementation is natural, but the pointless loop interrupts the otherwise direct return behavior.