Sample

pyint-56e61b2a25f5-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines270

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1010–1; higher is more readable
Mi0.5830–1; higher is more readable
LLOC73Logical lines; fewer is more readable
DeepSeek V4 Pro6.670–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.4030–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 Attribute: """ *Read-only* representation of an attribute. .. warning:: You should never instantiate this class yourself. The class has *all* arguments of `attr.ib` (except for ``factory`` which is only syntactic sugar for ``default=Factory(...)`` plus the following: - ``name`` (`str`): The name of the attribute. - ``alias`` (`str`): The __init__ parameter name of the attribute, after any explicit overrides and default private-attribute-name handling. - ``alias_is_default`` (`bool`): Whether the ``alias`` was automatically generated (``True``) or explicitly provided by the user (``False``). - ``inherited`` (`bool`): Whether or not that attribute has been inherited from a base class. - ``eq_key`` and ``order_key`` (`typing.Callable` or `None`): The callables that are used for comparing and ordering objects by this attribute, respectively. These are set by passing a callable to `attr.ib`'s ``eq``, ``order``, or ``cmp`` arguments. See also :ref:`comparison customization <custom-comparison>`. Instances of this class are frequently used for introspection purposes like: - `fields` returns a tuple of them. - Validators get them passed as the first argument. - The :ref:`field transformer <transform-fields>` hook receives a list of them. - The ``alias`` property exposes the __init__ parameter name of the field, with any overrides and default private-attribute handling applied. .. versionadded:: 20.1.0 *inherited* .. versionadded:: 20.1.0 *on_setattr* .. versionchanged:: 20.2.0 *inherited* is not taken into account for equality checks and hashing anymore. .. versionadded:: 21.1.0 *eq_key* and *order_key* .. versionadded:: 22.2.0 *alias* .. versionadded:: 26.1.0 *alias_is_default* For the full version history of the fields, see `attr.ib`. """ # These slots must NOT be reordered because we use them later for # instantiation. __slots__ = ( # noqa: RUF023 "name", "default", "validator", "repr", "eq", "eq_key", "order", "order_key", "hash", "init", "metadata", "type", "converter", "kw_only", "inherited", "on_setattr", "alias", "alias_is_default", ) def __init__( self, nam, def2, val, rep, cmp2, # XXX: unused, remove along with other cmp code. has, ini, inh, met=None, typ=None, con=None, kw=False, eq2=None, eq3=None, ord=None, order2=None, on=None, ali=None, alias2=None, ): eq2, eq3, ord, order2 = _determine_attrib_eq_order( cmp2, eq3 or eq2, order2 or ord, True ) # Cache this descriptor here to speed things up later. bound = _OBJ_SETATTR.__get__(self) # Despite the big red warning, people *do* instantiate `Attribute` # themselves. bound("name", nam) bound("default", def2) bound("validator", val) bound("repr", rep) bound("eq", eq2) bound("eq_key", eq3) bound("order", ord) bound("order_key", order2) bound("hash", has) bound("init", ini) bound("converter", con) bound( "metadata", ( types.MappingProxyType(dict(met)) # Shallow copy if met else _EMPTY_METADATA_SINGLETON ), ) bound("type", typ) bound("kw_only", kw) bound("inherited", inh) bound("on_setattr", on) bound("alias", ali) bound( "alias_is_default", ali is None if alias2 is None else alias2, ) def __setattr__(self, nam2, val2): raise FrozenInstanceError @classmethod def from2( cls, nam3: str, ca2: _CountingAttr, kw2: bool, typ2=None ): # The 'kw_only' argument is the class-level setting, and is used if the # attribute itself does not explicitly set 'kw_only'. # type holds the annotated value. deal with conflicts: if typ2 is None: typ2 = ca2.type elif ca2.type is not None: msg2 = f"Type annotation and type argument cannot both be present for '{nam3}'." raise ValueError(msg2) return cls( nam3, ca2._default, ca2._validator, ca2.repr, None, ca2.hash, ca2.init, False, ca2.metadata, typ2, ca2._converter, kw2 if ca2.kw_only is None else ca2.kw_only, ca2.eq, ca2.eq_key, ca2.order, ca2.order_key, ca2.on_setattr, ca2.alias, ca2.alias is None, ) # Don't use attrs.evolve since fields(Attribute) doesn't work def evo(self, **cha): """ Copy *self* and apply *changes*. This works similarly to `attrs.evolve` but that function does not work with :class:`attrs.Attribute`. It is mainly meant to be used for `transform-fields`. .. versionadded:: 20.3.0 """ import copy new2 = copy.copy(self) new2._setattrs(cha.items()) if "alias" in cha and "alias_is_default" not in cha: # Explicit alias provided -- no longer the default. _OBJ_SETATTR.__get__(new2)("alias_is_default", False) elif ( "name" in cha and "alias" not in cha # Don't auto-generate alias if the user picked picked the old one. and self.alias_is_default ): # Name changed, alias was auto-generated -- update it. _OBJ_SETATTR.__get__(new2)( "alias", _default_init_alias_for(new2.name) ) return new2 # Don't use _add_pickle since fields(Attribute) doesn't work def __getstate__(self): """ Play nice with pickle. """ return tuple( getattr(self, nam4) if nam4 != "metadata" else dict(self.metadata) for nam4 in self.__slots__ ) def __setstate__(self, sta): """ Play nice with pickle. """ if len(sta) < len(self.__slots__): # Pre-26.1.0 pickle without alias_is_default -- infer it # heuristically. state2 = dict(zip(self.__slots__, sta, strict=False)) alias3 = state2.get( "alias" ) is None or state2.get("alias") == _default_init_alias_for( state2["name"] ) sta = (*sta, alias3) self.set(zip(self.__slots__, sta, strict=True)) def set(self, name2): bound2 = _OBJ_SETATTR.__get__(self) for nam5, val3 in name2: if nam5 != "metadata": bound2(nam5, val3) else: bound2( nam5, ( types.MappingProxyType(dict(val3)) if val3 else _EMPTY_METADATA_SINGLETON ), )

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.5686.409−187.651
Source linesThe number of non-empty source lines.270+108
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.396−6.593

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.271−8.559
Indentation frequencyHow rapidly indentation changes from line to line.196+6.042
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.196−4.077
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.269.978+3.364
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.91.978+0.68
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.044+0.518
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.91.945−0.229

Intercept 0.07 + feature contributions = -2.191 (log-odds).
Score = sigmoid(-2.191) = 0.101.

Score0.583
Score73
Run 1

The code is heavily obfuscated by cryptic variable names (nam3, def2, ca2, eq2, eq3, etc.) and abbreviated method names (evo, from2, set), which severely obscures intent. The class structure itself is logical and the docstrings are clear, but the actual implementation works against readability. The long __init__ parameter list and positional argument passing in from2 make it error-prone and difficult to follow. Nesting is mostly flat, and action granularity is reasonable, but the pervasive use of short, non-descriptive identifiers and unexplained comments (e.g., 'XXX: unused, remove') reduce clarity. Reading flow is interrupted by constant mental mapping of abbreviated names to meaning. The metadata bound() blocks are repeated, adding unnecessary length. Overall, it reads like deliberately minified or legacy code, despite being part of a well-known library.

Run 2

The code relies heavily on cryptic, abbreviated variable names (nam, def2, val, rep, cmp2, has, ini, inh, ca2, kw2, etc.) and parameters like eq2/eq3/ord that obfuscate their purpose. The class docstring is helpful, but the method signatures and logic are hard to follow. There is moderate nesting, and some actions are split across multiple lines, but the overall flow is fragmented. The use of bound() to bypass __setattr__ is non-obvious. Despite comments and docstrings, the ambiguous naming and terse parameters significantly reduce readability.

Run 3

This code is extremely unreadable due to pervasive use of cryptic, abbreviated variable names (nam, def2, val, rep, cmp2, has, ini, inh, met, typ, con, kw, eq2, eq3, ord, order2, on, ali, alias2, nam2, nam3, etc.). These abbreviations obscure the meaning and intent of parameters and variables, forcing readers to constantly refer back to documentation or context. The code structure is moderately organized with clear class and method boundaries, and docstrings help explain the Attribute class purpose. However, the heavy use of positional arguments with short names makes method signatures difficult to understand. Nesting is relatively flat, which is positive, but the unclear naming overwhelms this advantage. Action granularity is reasonable—most lines perform a single logical operation—but the multiple assignments on single lines (e.g., eq2, eq3, ord, order2 = ...) and condensed logic in expressions reduce clarity. Reading flow is disrupted by the need to decode abbreviated parameters. The code is concise but at the cost of transparency; it reads almost obfuscated. Comments like 'XXX: unused' reveal technical debt. Overall, the lack of descriptive naming is the dominant factor making this code unreadable despite otherwise acceptable structure and length.

Run 1

Code Structure: Methods logically separate initialization, copying, and serialization, but evo calls _setattrs while the provided helper is named set, disrupting coherence. Nesting: Mostly shallow, with manageable conditionals and loops. Clarity of intent: Documentation and comments explain the class well, but abbreviated, numbered names such as def2, eq3, ca2, and nam5 obscure meaning; long positional argument lists require careful cross-referencing. Code length: Extensive documentation is useful, although repetitive assignments and compatibility handling make the implementation verbose. Action granularity: Generally one action per line, with a few compact multi-value assignments and conditional expressions increasing cognitive load. Reading flow: Method ordering is natural, but awkward line breaks, inconsistent naming, and comments referencing names absent from signatures interrupt comprehension.

Run 2

Code Structure: The class is logically divided into initialization, copying, serialization, and mutation helpers, but evo calls _setattrs while the shown helper is named set, making the organization harder to follow. Nesting: Mostly shallow, with manageable conditionals and loops. Clarity of intent: Detailed documentation and comments explain the purpose, but abbreviated, numbered names such as def2, eq3, ca2, and nam5 obscure meaning; numerous positional constructor arguments further complicate interpretation. Code length: Some length is justified by documentation and explicit field initialization, although repetitive assignments and awkward wrapping add reading overhead. Action granularity: Generally strong, with one assignment or operation per statement. Reading flow: Methods follow a sensible sequence, but inconsistent naming, dense conditional expressions, and dependencies on helpers outside the snippet interrupt otherwise natural progression.

Run 3

Code Structure: Responsibilities are separated into methods, with useful documentation, but slot-order dependencies and inconsistent helper naming complicate understanding. Nesting: Mostly shallow, with straightforward conditionals and one simple loop. Clarity of intent: The class purpose is well documented, but abbreviated and numbered identifiers such as def2, ca2, and eq3 obscure parameter meanings. The call to _setattrs contrasts confusingly with the defined set method. Code length: Some repetition is justified by explicit field initialization, though lengthy documentation and awkward wrapping slow scanning. Action granularity: Most lines perform a single action; tuple unpacking and conditional expressions occasionally compress multiple decisions. Reading flow: Method organization is logical, but the long positional constructor call, indirect setattr usage, and densely formatted compatibility logic require frequent cross-referencing.