Sample

pyint-0abbe8425059-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines58

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5320–1; higher is more readable
Mi0.2660–1; higher is more readable
LLOC29Logical lines; fewer is more readable
DeepSeek V4 Pro120–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.6680–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.58+23.2
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.506−6.759

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.59−1.053
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.108.983+0.954
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.108.898−0.947
Indentation frequencyHow rapidly indentation changes from line to line.39+0.612
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.039+0.566
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.39−0.474
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.57.864+0.399

Intercept 0.07 + feature contributions = 0.127 (log-odds).
Score = sigmoid(0.127) = 0.532.

Score0.266
Score29
Run 1

The code is generally readable but has formatting inconsistencies that detract from clarity. The imports are logically grouped, and the Factory class has a clear purpose with docstrings explaining its behavior. However, the code suffers from inconsistent spacing and alignment in the imports and exceptions sections, making it appear messy. The class methods are concise and serve distinct purposes, but the docstrings are somewhat verbose. The use of `__slots__` and pickle methods is clear, but the formatting inconsistencies and cramped import statements reduce overall readability. The code is neither deeply nested nor overly long, but the irregular spacing makes the structure harder to parse at a glance.

Run 2

The code defines a simple Factory class with clear intent and straightforward methods, earning points for clarity and flat structure. However, readability is undermined by the messy import section: several imports are crammed onto single lines with poor alignment, and imported names are intermingled with odd spacing. While the class itself is concise with one action per line, some methods and attributes lack blank lines separating logical blocks, slightly disrupting reading flow. The docstring is helpful but could be more concise. Overall, the core logic is readable, but formatting and organization issues reduce its score.

Run 3

The code is generally readable but has several issues. The import section is disorganized with misaligned imports (e.g., '_get_annotations, _lazy_is_generator' and 'DefaultAlreadySetError, FrozenInstanceError...') which disrupts readability. The Factory class is well-documented with a clear docstring explaining parameters, which improves intent clarity. Structure is logical with a single class per module section. However, the __getstate__ and __setstate__ methods use compressed loops instead of explicit field assignment, reducing clarity. Some lines contain multiple actions (e.g., 'for name, value in zip(self.__slots__, state, strict=True)'), and the spacing is inconsistent between top-level definitions. The code length is reasonable but could be shorter with simpler state handling. Overall nesting is flat, which is positive, but the formatting inconsistencies and deliberate compactness in some areas lower the readability score.

Run 1

Code Structure: Imports precede a cohesive Factory class, but inconsistent import formatting and missing blank lines between methods reduce organization. Nesting: Very shallow; only a simple loop adds indentation. Clarity of intent: The class docstring clearly explains factory and takes_self, and method names communicate initialization and serialization, though the pickle docstrings provide little detail. Code length: The implementation is concise, but numerous imports are unused in the shown snippet. Action granularity: Statements generally perform one action per line; crowded import lines are the main exception. Reading flow: Methods follow a natural initialization, serialization, and restoration sequence, but compressed spacing and irregular alignment interrupt scanning.

Run 2

Code Structure: Imports precede a focused class with logically organized initialization and serialization methods, though spacing between sections and methods is inconsistent. Nesting: Very shallow; only a simple loop appears in __setstate__. Clarity of intent: Descriptive names and docstrings clearly explain factory behavior and pickle support. Code length: The class is concise, but numerous imports unused in this snippet add clutter. Action granularity: Statements generally perform one action per line, although several imported names are awkwardly grouped on single lines. Reading flow: Method order is natural and implementation is straightforward, but missing blank lines and irregular import formatting interrupt scanning.

Run 3

Code Structure: The Factory class is logically organized, but numerous imports unrelated to the shown implementation and inconsistent spacing add clutter. Nesting: Methods remain flat, with only a simple loop in __setstate__. Clarity of intent: Descriptive names and the class docstring clearly explain factory behavior; serialization methods are straightforward, although their docstrings are vague. Code length: The implementation is concise, but imports and documentation dominate this small excerpt. Action granularity: Statements generally perform one action per line, though several imported names are awkwardly grouped on single lines. Reading flow: Method order is natural, but missing blank lines between some methods and irregular import formatting interrupt scanning.