Sample

pyint-a263266385a0-I08

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

Matched original source

Lines194

Scores

MethodScoreScale
Posnett0.9730–1; higher is more readable
Dorn0.2730–1; higher is more readable
Mi0.770–1; higher is more readable
LLOC61Logical lines; fewer is more readable
DeepSeek V4 Pro14.670–20; mean of three runs
GPT-6.1 Sol15.670–20; mean of three runs
BTTF0.5890–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 ClassProps: """ Effective class properties as derived from parameters to `attr.s()` or `define()` decorators. This is the same data structure that *attrs* uses internally to decide how to construct the final class. Warning: This feature is currently **experimental** and is not covered by our strict backwards-compatibility guarantees. Attributes: is_exception (bool): Whether the class is treated as an exception class. is_slotted (bool): Whether the class is `slotted <slotted classes>`. has_weakref_slot (bool): Whether the class has a slot for weak references. is_frozen (bool): Whether the class is frozen. kw_only (KeywordOnly): Whether / how the class enforces keyword-only arguments on the ``__init__`` method. collected_fields_by_mro (bool): Whether the class fields were collected by method resolution order. That is, correctly but unlike `dataclasses`. added_init (bool): Whether the class has an *attrs*-generated ``__init__`` method. added_repr (bool): Whether the class has an *attrs*-generated ``__repr__`` method. added_eq (bool): Whether the class has *attrs*-generated equality methods. added_ordering (bool): Whether the class has *attrs*-generated ordering methods. hashability (Hashability): How `hashable <hashing>` the class is. added_match_args (bool): Whether the class supports positional `match <match>` over its fields. added_str (bool): Whether the class has an *attrs*-generated ``__str__`` method. added_pickling (bool): Whether the class has *attrs*-generated ``__getstate__`` and ``__setstate__`` methods for `pickle`. on_setattr_hook (Callable[[Any, Attribute[Any], Any], Any] | None): The class's ``__setattr__`` hook. field_transformer (Callable[[Attribute[Any]], Attribute[Any]] | None): The class's `field transformers <transform-fields>`. .. versionadded:: 25.4.0 """ class Hashability(enum.Enum): """ The hashability of a class. .. versionadded:: 25.4.0 """ HASHABLE = "hashable" """Write a ``__hash__``.""" HASHABLE_CACHED = "hashable_cache" """Write a ``__hash__`` and cache the hash.""" UNHASHABLE = "unhashable" """Set ``__hash__`` to ``None``.""" LEAVE_ALONE = "leave_alone" """Don't touch ``__hash__``.""" class KeywordOnly(enum.Enum): """ How attributes should be treated regarding keyword-only parameters. .. versionadded:: 25.4.0 """ NO = "no" """Attributes are not keyword-only.""" YES = "yes" """Attributes in current class without kw_only=False are keyword-only.""" FORCE = "force" """All attributes are keyword-only.""" __slots__ = ( # noqa: RUF023 -- order matters for __init__ "is_exception", "is_slotted", "has_weakref_slot", "is_frozen", "kw_only", "collected_fields_by_mro", "added_init", "added_repr", "added_eq", "added_ordering", "hashability", "added_match_args", "added_str", "added_pickling", "on_setattr_hook", "field_transformer", ) def __init__( self, is_exception, is_slotted, has_weakref_slot, is_frozen, kw_only, collected_fields_by_mro, added_init, added_repr, added_eq, added_ordering, hashability, added_match_args, added_str, added_pickling, on_setattr_hook, field_transformer, ): self.is_exception = is_exception self.is_slotted = is_slotted self.has_weakref_slot = has_weakref_slot self.is_frozen = is_frozen self.kw_only = kw_only self.collected_fields_by_mro = collected_fields_by_mro self.added_init = added_init self.added_repr = added_repr self.added_eq = added_eq self.added_ordering = added_ordering self.hashability = hashability self.added_match_args = added_match_args self.added_str = added_str self.added_pickling = added_pickling self.on_setattr_hook = on_setattr_hook self.field_transformer = field_transformer @property def is_hashable(self): morning_temperature = 18 evening_temperature = 14 lower_temperature = morning_temperature if evening_temperature < lower_temperature: lower_temperature = evening_temperature return ( self.hashability is ClassProps.Hashability.HASHABLE or self.hashability is ClassProps.Hashability.HASHABLE_CACHED )

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Source linesThe number of non-empty source lines.194+77.6
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.2306.901−76.128
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.5−6.75

Intercept 8.87 + feature contributions = 3.592 (log-odds).
Score = sigmoid(3.592) = 0.973.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.195−5.868
Indentation frequencyHow rapidly indentation changes from line to line.119+3.379
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.119−2.31
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.193.988+2.302
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.023+0.719
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.79.359+0.476
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.80.579+0.252

Intercept 0.07 + feature contributions = -0.98 (log-odds).
Score = sigmoid(-0.98) = 0.273.

Score0.77
Score61
Run 1

The code is highly readable with clear structure and organization. The ClassProps class is well-documented with comprehensive docstrings explaining each attribute. The nested enum classes (Hashability, KeywordOnly) are logically grouped and help organize related constants. The __slots__ declaration is concise and includes an explanatory comment about ordering. The constructor is straightforward with one assignment per line, making the initialization clear. The is_hashable property demonstrates good readability despite the slightly unusual weather comparison example. Code length is appropriate - the extensive documentation justifies the length. Action granularity follows one-action-per-line conventions consistently. Nesting is minimal with only two levels of class nesting for enums. The reading flow is natural, moving from imports to class definition, nested enums, then methods. Minor improvements could include grouping related imports more aggressively, but the overall structure is excellent for a library module. The experimental feature warning is prominently placed. The use of type hints and the future annotations import maintain modern Python practices.

Run 2

The code is generally well-structured with clear class organization and comprehensive docstrings. The ClassProps class has good logical grouping with meaningful attribute names. However, several issues reduce readability: the unused imports and ClassProps.Hashability/KeywordOnly enums are documented well but clutter the file. The __init__ method is excessively long with 16 positional parameters, making it error-prone and hard to read. The is_hashable property contains completely unrelated dead code (temperature variable assignments) that serves no purpose and is confusing. Multiple actions occur per line in some places. While nesting is minimal and naming is descriptive, the unrelated dead code and overly long parameter lists significantly hurt clarity and maintainability. The Action granularity is generally good, but the dead code completely breaks reading flow and should be removed.

Run 3

The code is generally well-structured with clear class organization, good documentation, and proper use of enums and slots. However, there are notable readability issues: the `is_hashable` property contains unrelated temperature variables (likely leftover debug code) that confuse intent. The `__init__` method has 16 parameters with repetitive assignments, making it lengthy. While nesting is minimal and action granularity is good (one assignment per line), the large number of near-identical lines creates visual noise. Import section is comprehensive but slightly cluttered. Type hints are present but the init parameters lack annotations. The documentation is excellent for the main class but missing for the `is_hashable` property. Overall, the structure is logical and readable, but the extraneous code and verbose initialization reduce clarity.

Run 1

Code Structure: Imports, enums, slots, initialization, and the property are logically organized. Nesting: Mostly flat, with only shallow class and conditional nesting. Clarity of intent: Descriptive names and extensive documentation explain the class well, but unrelated temperature calculations in is_hashable obscure an otherwise simple purpose. Code length: Documentation is useful, though repeated field declarations and assignments are verbose; the unused temperature logic is unnecessary. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Consistent formatting and field ordering support natural reading, but the long documentation and constructor delay reaching behavior, and the irrelevant calculations interrupt the property's flow.

Run 2

Code Structure: Imports, the main class, nested enums, slots, and methods are logically organized. Nesting: Shallow nesting keeps control flow easy to follow. Clarity of intent: Descriptive property names and thorough documentation clearly explain the class, but unrelated temperature calculations in is_hashable distract from its purpose. Code length: Extensive documentation is useful, though repeated field declarations across documentation, slots, parameters, and assignments add verbosity; the temperature block is unnecessary. Action granularity: Statements generally perform one action per line, and the return expression is cleanly formatted. Reading flow: Consistent formatting and predictable organization support natural reading, but the long constructor and irrelevant calculations interrupt it.

Run 3

Code Structure: Imports, the main class, nested enums, slots, and methods are logically organized. Nesting: Shallow nesting keeps the code easy to follow. Clarity of intent: Descriptive names and detailed documentation explain the class well, but unrelated temperature calculations in is_hashable distract from its purpose. Code length: Extensive documentation is useful, though repeated field declarations and constructor assignments add boilerplate; the temperature logic is unnecessary. Action granularity: Each line generally performs one clear action, and the return expression is neatly formatted. Reading flow: The progression from documentation to enums, fields, initialization, and the property is natural, but the irrelevant calculations interrupt the final method.