Sample

pyint-7fab4bf9e369-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines66

Scores

MethodScoreScale
Posnett0.0020–1; higher is more readable
Dorn0.6970–1; higher is more readable
Mi0.5350–1; higher is more readable
LLOC29Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.7190–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 Factory: """ Stores a factory callable. If passed as the default value to `attrs.field`, the factory is used to generate a new value. Args: factory (typing.Callable): A callable that takes either none or exactly one mandatory positional argument depending on *takes_self*. takes_self (bool): Pass the partially initialized instance that is being initialized as a positional argument. .. versionadded:: 17.1.0 *takes_self* """ __slots__ = ("factory", "takes_self") def __init__(self, factory, takes_self=False): self.factory = factory self.takes_self = takes_self def __getstate__(self): """ Play nice with pickle. """ return tuple(getattr(self, name) for name in self.__slots__) def __setstate__(self, state): """ Play nice with pickle. """ for name, value in zip(self.__slots__, state, strict=True): setattr(self, name, value)

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.1056.775−34.874
Source linesThe number of non-empty source lines.66+26.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.513−6.769

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.67−1.336
Indentation frequencyHow rapidly indentation changes from line to line.46+0.854
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.46−0.635
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.039+0.566
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.65.833+0.51
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.77+0.404
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.74.612+0.399

Intercept 0.07 + feature contributions = 0.833 (log-odds).
Score = sigmoid(0.833) = 0.697.

Score0.535
Score29
Run 1

The code demonstrates excellent readability through clear structure and organization. Imports are logically grouped with a mix of standard library, third-party, and local modules. The Factory class has a well-documented purpose with a clear docstring explaining its usage and parameters. Each method has a single, focused responsibility - __init__, __getstate__, and __setstate__ each perform one clear action. The code uses modern Python features appropriately (__slots__, zip with strict=True, type hints) without sacrificing clarity. Naming conventions are consistent and descriptive. The use of __slots__ reduces memory overhead while the concise implementation avoids unnecessary verbosity. Comments are minimal but meaningful, with version annotations where relevant. The only minor deduction is that some context about the broader attrs library would help understand this class's role in the larger system, but within its scope, it's exceptionally clear and well-structured.

Run 2

The code is highly readable. It has a clear, single-purpose class with a well-structured docstring, minimal but effective comments for pickle support methods, and flat, non-nested logic. Imports are organized and explicit, using `__future__` and grouped stdlib/application imports. Each action is concise, with no unnecessary complexity or length. The reading flow is logical: class docstring first, then slots, constructor, and serialization helpers. Minor deductions for a few unused imports and a slightly long import block, but overall this is very clean, maintainable code.

Run 3

The code is highly readable. It follows a logical structure with clear section separation: imports, class definition, docstrings, and methods. Nesting is minimal—only shallow context managers/loops appear, and the class is flat. Intent is evident through descriptive naming (Factory, takes_self) and comprehensive docstrings that explain purpose, arguments, and version notes. Code length is appropriate; no unnecessary verbosity. Action granularity is mostly one action per line, though the __getstate__ and __setstate__ methods each use a single return/loop line with a tuple comprehension or zip, which is still clear but slightly dense. Reading flow is natural: the class starts with a docstring, then slots, then constructor, then pickle-support methods. The use of __slots__ and strict=True in zip are modern and precise. Overall, this is well-structured, self-documenting code that balances clarity and conciseness effectively.

Run 1

Code Structure: The class is logically organized into documentation, slots, initialization, and serialization methods, though many imports are unused in this excerpt. Nesting: Methods are flat, with only a single shallow loop. Clarity of intent: Descriptive names and a detailed class docstring clearly explain the factory's purpose; serialization docstrings are somewhat informal. Code length: The implementation is concise, although the extensive import block outweighs the small class shown. Action granularity: Statements generally perform one action per line, and the generator expression is straightforward. Reading flow: The progression from initialization to state serialization and restoration is natural, but additional spacing between import groups and the class would improve scanning.

Run 2

Code Structure: Imports and a single focused class are logically organized, although many imports are unused in this snippet. Nesting: Methods are flat, with only one shallow loop. Clarity of intent: The class docstring clearly explains factory behavior, and descriptive names make initialization and serialization easy to understand; the pickle method docstrings are less precise. Code length: The implementation is concise, though the extensive import block is disproportionate to the displayed functionality. Action granularity: Each statement performs one clear action, and the tuple comprehension remains straightforward. Reading flow: The sequence from documentation to slots, initialization, and serialization is natural, with consistent formatting and spacing.

Run 3

Code Structure: Imports and a single focused class are logically organized, although many imports are unused in this excerpt. Nesting: Methods are flat, with only one shallow loop. Clarity of intent: Descriptive names and a detailed class docstring clearly explain factory behavior; pickle method docstrings are less specific about state serialization. Code length: The implementation is concise, though the extensive imports and documentation outweigh the small amount of executable code. Action granularity: Each statement performs one clear action, and the generator expression remains easy to follow. Reading flow: The class progresses naturally from initialization to state retrieval and restoration. Additional blank lines between import groups and before the class would improve visual separation.