Sample

pyint-732f72fd8c84-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines189

Scores

MethodScoreScale
Posnett0.9980–1; higher is more readable
Dorn0.280–1; higher is more readable
Mi0.770–1; higher is more readable
LLOC56Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.640–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): 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.189+75.6
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.2161.997−71.346
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.501−6.752

Intercept 8.87 + feature contributions = 6.372 (log-odds).
Score = sigmoid(6.372) = 0.998.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.190−5.691
Indentation frequencyHow rapidly indentation changes from line to line.114+3.206
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.188.988+2.232
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.114−2.195
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.023+0.721
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.79.3+0.475
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.911+0.238

Intercept 0.07 + feature contributions = -0.944 (log-odds).
Score = sigmoid(-0.944) = 0.28.

Score0.77
Score56
Run 1

The code is highly readable with clear structure and intent. The ClassProps class uses __slots__ and has a straightforward __init__ that maps parameters to attributes one per line. The nested enums (Hashability, KeywordOnly) are logically grouped and well-documented. Each enum value has a docstring explaining its purpose. The docstring for ClassProps is comprehensive, documenting all attributes with types and descriptions. The is_hashable property is concise and readable. Import organization is clean, using standard library, third-party, and local imports in separate blocks. Minor deductions: the __init__ method is somewhat long (16 parameters) but unavoidable given the class's purpose as a data container; the enum value assignments use string values rather than auto() which is stylistic but acceptable. Overall, the code demonstrates excellent organization, minimal nesting, clear intent, and natural reading flow.

Run 2

The code demonstrates strong readability through clear structure and organization. The ClassProps class is logically organized with nested enums (Hashability, KeywordOnly) grouped before the main class definition, which aids comprehension. The docstring is comprehensive, clearly explaining each attribute and its purpose. The __init__ method uses flat, straightforward parameter-to-attribute assignment without nesting or conditional logic. Each assignment occupies a single line, maintaining excellent action granularity. The code length is proportionate to the number of attributes handled - 16 parameters and assignments is verbose but necessary given the class's purpose. The __slots__ tuple is well-commented, explaining why ordering matters. The property method is concise and readable. Minor deductions: the import block is lengthy and includes several unused imports (abc, sys, types, etc.), which could confuse readers about actual dependencies. The nested enum classes within ClassProps slightly increase cognitive load, though they're appropriately scoped. Overall, the code exhibits clear intent, natural reading flow, and good structural organization.

Run 3

The code is generally well-structured and readable. It has clear sections: imports, class docstring with detailed attribute documentation, nested enums with their own docstrings, and a straightforward __init__ method. The nesting is minimal and logical. The intent is clearly expressed through descriptive naming and comprehensive documentation. The __init__ is repetitive but follows a consistent pattern, making it predictable and easy to scan. The is_hashable property is concise and readable. Some improvements could be made: the __init__ could use a dataclass-like pattern to reduce boilerplate, and the many boolean parameters could be grouped into smaller configuration objects to improve clarity. The docstrings are excellent but quite verbose, which increases line count though not necessarily reducing readability. Overall, it's professional, maintainable code with good structure and clear intent.

Run 1

Code Structure: Logically organized into a documented class, related nested enums, slots, initialization, and a derived property. Nesting: Shallow and purposeful; nested enums group related concepts without complicating control flow. Clarity of intent: Descriptive names and comprehensive documentation make the class's purpose and individual properties clear, though constructor type annotations would improve clarity. Code length: Verbose documentation and repeated field declarations across slots, parameters, and assignments increase length, but most repetition serves an understandable purpose. Action granularity: Each assignment and enum declaration performs one clear action; the property expression is neatly formatted. Reading flow: Natural progression from conceptual documentation to implementation, with consistent formatting. The large import block includes many names unused in this snippet, adding some distraction.

Run 2

Code Structure: Imports, documentation, nested enums, slots, initialization, and the derived property are logically organized. Nesting: Shallow nesting is limited to meaningful enum definitions and methods. Clarity of intent: Descriptive names and thorough documentation make the class's purpose and individual properties clear; missing constructor type annotations slightly weaken clarity. Code length: The implementation is straightforward, but extensive documentation and repeated field names across slots, parameters, and assignments increase scanning effort. Action granularity: Each assignment and enum declaration performs one clear action, with no compressed multi-action statements. Reading flow: The progression from class description to supported values, stored fields, initialization, and computed property is natural. Minor spacing limitations around imports and the class, plus the long constructor parameter list, prevent a perfect score.

Run 3

Code Structure: Logically organized into documented class properties, related enums, slots, initialization, and a derived property. Nesting: Shallow and appropriate; nested enums group related concepts without complicating control flow. Clarity of intent: Descriptive names and comprehensive docstrings make the purpose clear, although constructor type annotations would improve precision. Code length: The implementation is straightforward, but repeating 16 fields across documentation, slots, parameters, and assignments adds substantial verbosity. Action granularity: Each assignment performs one action, and enum values and property logic are easy to inspect. Reading flow: The progression from documentation to definitions and implementation is natural, though the lengthy opening docstring delays reaching executable code. Overall, highly readable with minor repetition and typing limitations.