Sample

pyint-a4685cb58319-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines195

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3460–1; higher is more readable
Mi0.7380–1; higher is more readable
LLOC58Logical lines; fewer is more readable
DeepSeek V4 Pro140–20; mean of three runs
GPT-6.1 Sol16.670–20; mean of three runs
BTTF0.480–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 _CountingAttr: """ Intermediate representation of attributes that uses a counter to preserve the order in which the attributes have been defined. *Internal* data structure of the attrs library. Running into is most likely the result of a bug like a forgotten `@attr.s` decorator. """ __slots__ = ( "_converter", "_default", "_validator", "alias", "counter", "eq", "eq_key", "hash", "init", "kw_only", "metadata", "on_setattr", "order", "order_key", "repr", "type", ) __attrs_attrs__ = ( *tuple( Attribute( name=name, alias=_default_init_alias_for(name), default=NOTHING, validator=None, repr=True, cmp=None, hash=True, init=True, kw_only=False, eq=True, eq_key=None, order=False, order_key=None, inherited=False, on_setattr=None, ) for name in ( "counter", "_default", "repr", "eq", "order", "hash", "init", "on_setattr", "alias", ) ), Attribute( name="metadata", alias="metadata", default=None, validator=None, repr=True, cmp=None, hash=False, init=True, kw_only=False, eq=True, eq_key=None, order=False, order_key=None, inherited=False, on_setattr=None, ), ) cls_counter = 0 def __init__( self, default, validator, repr, cmp, hash, init, converter, metadata, type, kw_only, eq, eq_key, order, order_key, on_setattr, alias, ): _CountingAttr.cls_counter += 1 self.counter = _CountingAttr.cls_counter self._default = default self._validator = validator self._converter = converter self.repr = repr self.eq = eq self.eq_key = eq_key self.order = order self.order_key = order_key self.hash = hash self.init = init self.metadata = metadata self.type = type self.kw_only = kw_only self.on_setattr = on_setattr self.alias = alias def validator(self, meth): """ Decorator that adds *meth* to the list of validators. Returns *meth* unchanged. .. versionadded:: 17.1.0 """ if self._validator is None: self._validator = meth else: self._validator = and_(self._validator, meth) return meth def default(self, meth): """ Decorator that allows to set the default for an attribute. Returns *meth* unchanged. Raises: DefaultAlreadySetError: If default has been set before. .. versionadded:: 17.1.0 """ if self._default is not NOTHING: raise DefaultAlreadySetError self._default = Factory(meth, takes_self=True) return meth def converter(self, meth): """ Decorator that appends *meth* to the list of converters. Returns *meth* unchanged. .. versionadded:: 26.2.0 """ decorated_converter = Converter( lambda value, _self, field: meth(_self, field, value), takes_self=True, takes_field=True, ) if self._converter is None: self._converter = decorated_converter else: self._converter = pipe(self._converter, decorated_converter) return meth

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.3811.44−125.778
Source linesThe number of non-empty source lines.195+78
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.037−6.056

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.196−5.903
Indentation frequencyHow rapidly indentation changes from line to line.168+5.074
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.168−3.434
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.194.987+2.316
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.424
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.75.342+0.411
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.76.964+0.405

Intercept 0.07 + feature contributions = -0.638 (log-odds).
Score = sigmoid(-0.638) = 0.346.

Score0.738
Score58
Run 1

The code is generally well-structured and readable. It uses clear naming conventions, docstrings, and type hints. The class definition and methods are logically organized, and the use of `__slots__` improves clarity. However, there are some readability challenges. The `__attrs_attrs__` tuple construction is complex and visually dense, mixing comprehensions with explicit `Attribute` calls. The long parameter lists in `__init__` and `Attribute` reduce readability. The code is mostly flat with minimal deep nesting, and each line tends to perform one action, which aids comprehension. The reading flow is mostly natural, but the large block of attribute definitions could be broken down for better scannability. Overall, it is readable but could be improved by simplifying the meta-attribute construction and reducing verbosity in parameter handling.

Run 2

The code exhibits moderate readability but suffers from several issues. The class structure has a logical purpose, but the __attrs_attrs__ definition is dense and convoluted, with deeply nested tuple/generator expressions that are hard to follow. The __init__ method has an excessive number of parameters (15), making the intent unclear and the interface difficult to grasp. Method bodies are short and relatively clear, which helps, but the overall action granularity is uneven — some lines pack multiple operations while others are sparse. Nesting, especially in __attrs_attrs__, significantly hampers comprehension. Reading flow is disrupted by the lengthy parameter lists and complex data structure initialization. The code length is not overly verbose for the functionality, but conciseness does not compensate for the structural opacity. The clarity of intent is undermined by the heavy reliance on internal framework conventions without explanatory comments in the trickiest sections.

Run 3

The code is highly readable. It uses clear imports, a logical class structure, and descriptive method names with concise docstrings explaining behavior and exceptions. The action granularity is mostly one action per line, especially in __init__. The __attrs_attrs__ construction uses a tuple generator and explicit Attribute calls, which is structured though slightly verbose. Overall nesting is flat, and intent is clear.

Run 1

Code Structure: Clearly organized into imports, class metadata, initialization, and focused decorator methods. Nesting: Shallow overall; the attribute-building comprehension is the densest section. Clarity of intent: Descriptive names and useful docstrings explain ordering and decorator behavior, although external symbols and the converter lambda require additional context. Code length: Mostly justified, but repeated Attribute configuration and the long constructor make the class verbose. Action granularity: Statements generally perform one action per line; the lambda and expanded tuple comprehension are modest exceptions in complexity. Reading flow: Consistent formatting and straightforward branches support natural reading, though substantial metadata before the methods delays reaching the core behavior.

Run 2

Code Structure: The class is logically organized into metadata, initialization, and small decorator methods, although the large import block and attribute declaration add overhead. Nesting: Control flow is shallow, with simple conditionals; the tuple expansion and comprehension are somewhat denser. Clarity of intent: Descriptive names and useful docstrings explain ordering and decorator behavior, though external helpers and sentinel values require library context. Code length: The lengthy constructor and repeated Attribute arguments are verbose but mostly justified by explicit configuration. Action granularity: Each assignment and operation occupies its own line, making state changes easy to follow. Reading flow: Consistent formatting and method organization support natural reading, but substantial metadata before the methods delays reaching the core behavior.

Run 3

Code Structure: The class logically groups attribute storage, initialization, and decorator helpers, although the broad import block and lengthy metadata declaration add noise. Nesting: Methods remain shallow, with straightforward conditionals; the nested tuple construction is somewhat harder to scan. Clarity of intent: Descriptive method names and useful docstrings explain the purpose, but external symbols and specialized attrs conventions require context. Code length: Decorator methods are concise, while repeated Attribute arguments and the large constructor introduce verbosity. Action granularity: Statements generally perform one action per line, making state changes easy to follow. Reading flow: Consistent formatting and the progression from class configuration to initialization and helper methods support natural reading, though the extensive configuration delays the behavioral code.