Sample

pyint-8b84b8f3b13e-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines197

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3340–1; higher is more readable
Mi0.7380–1; higher is more readable
LLOC59Logical lines; fewer is more readable
DeepSeek V4 Pro10.670–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.4630–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 not (self._validator is None): self._validator = and_(self._validator, meth) else: 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 not (self._default is not NOTHING): pass else: 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 not (self._converter is None): self._converter = pipe(self._converter, decorated_converter) else: 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.3901.304−128.743
Source linesThe number of non-empty source lines.197+78.8
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.034−6.051

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.198−5.974
Indentation frequencyHow rapidly indentation changes from line to line.170+5.143
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.170−3.48
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.196.962+2.343
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.414
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.96+0.406
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.73.874+0.387

Intercept 0.07 + feature contributions = -0.691 (log-odds).
Score = sigmoid(-0.691) = 0.334.

Score0.738
Score59
Run 1

The code demonstrates clear organization with logical imports and a well-documented class. The __init__ method is verbose but readable due to consistent parameter naming and straightforward assignments. However, several issues reduce readability: the inverted conditional pattern 'if not (condition): pass else: raise' in validator/default/converter methods is unnecessarily convoluted and should use standard positive conditionals with early raises. The __attrs_attrs__ definition is very long with repetitive Attribute() constructor calls, making it difficult to scan. The class has many parameters (15+ in __init__), suggesting potential for refactoring into smaller config objects. Nesting is generally flat, and intent is mostly clear through good docstrings. Line-by-line action granularity is reasonable, but the conditional inversions break natural reading flow. Overall, the code is maintainable by experienced developers familiar with the domain, but could benefit from simplifying control flow and reducing repetition in attribute definitions.

Run 2

The code is poorly readable. It contains deeply nested structures, especially in the __attrs_attrs__ tuple with generator expressions and a large tuple expansion. The __init__ method has too many parameters with repetitive assignments, reducing clarity and increasing cognitive load. Actions are compacted into long, dense expressions that combine multiple steps per line. The control flow in validator/default/converter methods uses awkward inverted conditions (e.g., `if not (x is None)`), which obscure intent. While imports and class structure are organized, the overall layout suffers from excessive verbosity, unclear separation of concerns, and a lack of concise explanatory comments where needed. The reading flow is disorienting due to inconsistent spacing, long signatures, and a mix of abstractions that make it hard to follow the logical path.

Run 3

The code shows some organizational strengths: clear imports, a docstring, __slots__, and a helper structure in __attrs_attrs__. However, readability suffers from excessive length in __init__ with 16 parameters, making intent hard to follow. The heavy use of negated conditionals like 'if not (self._validator is None)' with empty pass/else branches is awkward and obscures flow. Names like '_CountingAttr', 'cls_counter', and 'eq_key' require domain knowledge but are consistent. Overall, structure is logical but verbose; nesting is flat but long; clarity and reading flow are mixed. Action granularity is generally one action per line, which helps, but the convoluted conditionals and large __attrs_attrs__ tuple reduce readability. Score reflects a codebase that is maintainable but not immediately intuitive.

Run 1

Code Structure: The class is logically organized into metadata, initialization, and decorator methods, though the large metadata declaration dominates the snippet. Nesting: Mostly shallow, with simple conditional branches; the nested tuple comprehension requires more attention. Clarity of intent: Descriptive names and useful docstrings explain the purpose, but negated conditions such as `if not (self._default is not NOTHING)` obscure straightforward checks. Code length: The lengthy constructor and repeated Attribute configuration add verbosity, while the default method's empty `pass` branch is unnecessary. Action granularity: Statements generally perform one action per line, making assignments and state changes easy to follow. Reading flow: Consistent formatting and method grouping support natural reading, but the extensive imports, externally defined helpers, and bulky class metadata delay reaching the core behavior.

Run 2

Code Structure: The class is logically organized into metadata, initialization, and focused decorator methods, though the large import block and verbose attribute definitions add clutter. Nesting: Control flow is shallow; the tuple construction is moderately dense but contained. Clarity of intent: Descriptive method names and docstrings explain responsibilities well. However, negated conditions such as `if not (self._default is not NOTHING)` obscure simple checks, and referenced helpers require external context. Code length: Repeated Attribute arguments and the long constructor make the code verbose; the pass/else error check adds unnecessary lines. Action granularity: Assignments and operations generally occupy separate lines, making state changes easy to inspect. Reading flow: The progression from class configuration to initialization and behavior is natural, but double negatives, built-in-shadowing parameter names, and extensive boilerplate interrupt otherwise straightforward reading.

Run 3

Code Structure: The class is logically organized into metadata, initialization, and decorator methods, although the large import block adds clutter. Nesting: Mostly flat, with shallow conditionals; the nested tuple comprehension is somewhat harder to scan. Clarity of intent: Descriptive names and detailed docstrings explain the purpose well, but negated conditions such as `if not (self._default is not NOTHING)` obscure simple checks. Code length: Repeated Attribute configuration and the long constructor create substantial boilerplate; the empty `pass` branch is unnecessary. Action granularity: Statements generally perform one action per line, making assignments easy to follow. Reading flow: Consistent formatting and method boundaries support natural reading, but verbose metadata construction, double negatives, and dependencies defined outside the snippet interrupt comprehension.