Sample

pyint-1fa5abadd0ac-I06

Invert eligible conditions and exchange their branches

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 Pro17.670–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 well-structured and highly readable. It follows a clear logical order: imports, class definition, docstrings, methods. Nesting is minimal, with class methods flat and separated. Intent is clearly communicated through descriptive docstrings and parameter names. The code is concise but not overly so, with no unnecessary repetition. Action granularity is good—each line typically does one thing, such as `return tuple(getattr(self, name) for name in self.__slots__)`. Reading flow is natural and consistent with Python conventions. Minor deductions: the use of `zip(..., strict=True)` may be less familiar to some readers, and the `Factory` class could benefit from a type hint for `factory`, though this is not a major readability issue.

Run 3

The code is well-structured with clear separation between imports, class definition, and methods. There is minimal nesting and each method has a single, clear responsibility. The docstrings effectively communicate intent, especially for the Factory class and its pickle-related methods. Variable names are descriptive and consistent. The Factory class uses class-level attributes and slots appropriately for performance and clarity. Some minor improvements could include adding docstrings to individual attributes and slightly condensing redundant docstrings (e.g., 'Play nice with pickle' repeated), but overall the code is highly readable, concise, and follows Python best practices.

Run 1

Code Structure: The Factory class is logically organized, with initialization followed by serialization methods; however, many imports are unused in this snippet. Nesting: Methods remain shallow, with only a single loop. Clarity of intent: Descriptive names and a detailed class docstring clearly explain factory behavior, although the pickle method docstrings provide little detail. Code length: The implementation is concise, but the import list is disproportionate to the shown functionality. Action granularity: Each statement performs one clear action; the generator expression is compact and readable. Reading flow: The class reads naturally from purpose to initialization to state handling, though additional spacing between import groups and the class would improve visual separation.

Run 2

Code Structure: The class is logically organized, with slots, initialization, and serialization methods clearly separated; many imports are unused in this excerpt and add clutter. Nesting: Control flow is shallow, with only a simple loop in __setstate__. Clarity of intent: Descriptive names and a detailed class docstring explain the factory's purpose and takes_self behavior, although the pickle-method docstrings are informal and do not explain the slot-based state representation. Code length: The implementation is concise; documentation is useful but relatively long compared with the executable code. Action granularity: Each statement performs a single clear action, and the tuple comprehension remains straightforward. Reading flow: Methods follow a natural order, making the class easy to scan, though the extensive import block delays reaching the relevant implementation.

Run 3

Code Structure: The class is logically organized into initialization and serialization methods, although the many unused imports distract from this isolated snippet. Nesting: Methods are flat, with only one simple loop. Clarity of intent: Descriptive names and a detailed class docstring explain the factory's purpose and takes_self behavior; serialization docstrings are less specific. Code length: Implementation is concise, though imports and documentation dominate the short class. Action granularity: Each statement performs a single clear action, and the generator expression is straightforward. Reading flow: Methods follow a natural order, and consistent formatting supports easy scanning; a clearer separation between imports and the class would improve presentation.