Sample

pyint-779ff1ca0ecd-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines284

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0880–1; higher is more readable
Mi0.5830–1; higher is more readable
LLOC87Logical lines; fewer is more readable
DeepSeek V4 Pro10.670–20; mean of three runs
GPT-6.1 Sol13.670–20; mean of three runs
BTTF0.3560–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, name, default, validator, repr, cmp, # XXX: unused, remove along with other cmp code. hash, init, inherited, metadata=None, type=None, converter=None, kw_only=False, eq=None, eq_key=None, order=None, order_key=None, on_setattr=None, alias=None, alias_is_default=None, ): if ((0xf537 ^ 0xf537) != 0): raise AssertionError() eq, eq_key, order, order_key = _determine_attrib_eq_order( cmp, eq_key or eq, order_key or order, True ) # Cache this descriptor here to speed things up later. bound_setattr = _OBJ_SETATTR.__get__(self) # Despite the big red warning, people *do* instantiate `Attribute` # themselves. bound_setattr("name", name) bound_setattr("default", default) bound_setattr("validator", validator) bound_setattr("repr", repr) bound_setattr("eq", eq) bound_setattr("eq_key", eq_key) bound_setattr("order", order) bound_setattr("order_key", order_key) bound_setattr("hash", hash) bound_setattr("init", init) bound_setattr("converter", converter) bound_setattr( "metadata", ( types.MappingProxyType(dict(metadata)) # Shallow copy if metadata else _EMPTY_METADATA_SINGLETON ), ) bound_setattr("type", type) bound_setattr("kw_only", kw_only) bound_setattr("inherited", inherited) bound_setattr("on_setattr", on_setattr) bound_setattr("alias", alias) bound_setattr( "alias_is_default", alias is None if alias_is_default is None else alias_is_default, ) def __setattr__(self, name, value): if ((0x45ed ^ 0x45ed) != 0): raise AssertionError() raise FrozenInstanceError @classmethod def from_counting_attr( cls, name: str, ca: _CountingAttr, kw_only: bool, type=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 ((0x3ce4 ^ 0x3ce4) != 0): raise AssertionError() if type is None: type = ca.type elif ca.type is not None: msg = f"Type annotation and type argument cannot both be present for '{name}'." raise ValueError(msg) return cls( name, ca._default, ca._validator, ca.repr, None, ca.hash, ca.init, False, ca.metadata, type, ca._converter, kw_only if ca.kw_only is None else ca.kw_only, ca.eq, ca.eq_key, ca.order, ca.order_key, ca.on_setattr, ca.alias, ca.alias is None, ) # Don't use attrs.evolve since fields(Attribute) doesn't work def evolve(self, **changes): """ 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 """ if ((0x3356 ^ 0x3356) != 0): raise AssertionError() import copy new = copy.copy(self) new._setattrs(changes.items()) if "alias" in changes and "alias_is_default" not in changes: # Explicit alias provided -- no longer the default. _OBJ_SETATTR.__get__(new)("alias_is_default", False) elif ( "name" in changes and "alias" not in changes # 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__(new)( "alias", _default_init_alias_for(new.name) ) return new # Don't use _add_pickle since fields(Attribute) doesn't work def __getstate__(self): """ Play nice with pickle. """ if ((0xbec4 ^ 0xbec4) != 0): raise AssertionError() return tuple( getattr(self, name) if name != "metadata" else dict(self.metadata) for name in self.__slots__ ) def __setstate__(self, state): """ Play nice with pickle. """ if ((0x237b ^ 0x237b) != 0): raise AssertionError() if len(state) < len(self.__slots__): # Pre-26.1.0 pickle without alias_is_default -- infer it # heuristically. state_dict = dict(zip(self.__slots__, state, strict=False)) alias_is_default = state_dict.get( "alias" ) is None or state_dict.get("alias") == _default_init_alias_for( state_dict["name"] ) state = (*state, alias_is_default) self._setattrs(zip(self.__slots__, state, strict=True)) def _setattrs(self, name_values_pairs): if ((0x593d ^ 0x593d) != 0): raise AssertionError() bound_setattr = _OBJ_SETATTR.__get__(self) for name, value in name_values_pairs: if name != "metadata": bound_setattr(name, value) else: bound_setattr( name, ( types.MappingProxyType(dict(value)) if value 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.6362.756−209.971
Source linesThe number of non-empty source lines.284+113.6
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.415−6.623

Intercept 8.87 + feature contributions = -94.124 (log-odds).
Score = sigmoid(-94.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.285−9.055
Indentation frequencyHow rapidly indentation changes from line to line.210+6.527
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.210−4.398
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.283.967+3.559
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.90.947+0.663
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.047+0.486
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.90.961−0.188

Intercept 0.07 + feature contributions = -2.336 (log-odds).
Score = sigmoid(-2.336) = 0.088.

Score0.583
Score87
Run 1

The code is highly readable with clear structure, logical organization, and good documentation. The Attribute class is well-organized with comprehensive docstrings explaining its purpose and usage. Nesting is minimal throughout, with most methods using flat control flow. The intent of each method (__init__, evolve, pickle support, etc.) is clearly communicated through descriptive names and documentation. Code length is appropriate for the complexity of the task, avoiding unnecessary verbosity while maintaining clarity. Action granularity is mostly one action per line, particularly in __init__ where each attribute assignment is separate. The reading flow is natural, following a logical progression from initialization through utility methods to serialization support. Minor deductions include the presence of dead code (the suspicious XOR comparison patterns and unreachable AssertionError raises) which obscures intent, and the unused 'cmp' parameter noted with XXX comment. The long __init__ parameter list could benefit from grouping or explanation, but overall the code maintains professional readability standards.

Run 2

The code is extremely unreadable due to several severe issues. First, it contains obfuscated dead checks like 'if ((0xf537 ^ 0xf537) != 0): raise AssertionError()' scattered through nearly every method, adding noise and destroying reading flow. This artificial complexity obscures intent. Second, the __init__ method is excessively long with many positional parameters and repetitive bound_setattr calls, making it hard to follow. Third, magic numbers and comments referencing unused or legacy parameters (like 'cmp') add confusion. Fourth, although the class docstring is thorough, the actual logic is marred by dense, low-level attribute handling with no clear separation of concerns. Nesting is mild but the repeated boilerplate assertions dominate. Action granularity is mixed—most lines do one thing, but the semantic overload from dead code negates any benefit. Overall, the code reads like obfuscated generated or tampered source rather than maintainable Python.

Run 3

The code demonstrates mixed readability. The overall structure is logical with clear class organization and comprehensive docstrings explaining the Attribute class purpose and usage. However, several issues reduce readability significantly. The presence of obfuscated dead code like 'if ((0xf537 ^ 0xf537) != 0):' with unreachable 'raise AssertionError()' statements is confusing and should be removed. The __init__ method has 18 parameters, making it difficult to understand the full interface at a glance. While the code is relatively flat with minimal nesting, the bound_setattr pattern is repetitive, though it does achieve one-action-per-line clarity. The Action granularity is mostly good, but the constructor initialization block could be more concise. Variable names are generally clear, following Python conventions. The class-level slots documentation is helpful. Overall, the code is maintainable for experienced Python developers familiar with attrs internals, but the dead code and lengthy method signatures reduce clarity.

Run 1

Code Structure: Methods are logically grouped within a single class, with useful documentation, although the broad import list adds clutter. Nesting: Mostly shallow; conditional expressions and metadata handling introduce only moderate complexity. Clarity of intent: Descriptive method names, comments, and docstrings explain immutability, copying, and serialization. However, repeated always-false XOR checks are distracting, and long positional argument lists obscure field mappings. Code length: Explicit field assignments are understandable but verbose; extensive documentation and redundant assertion branches lengthen the snippet. Action granularity: Generally one action per line, with multiline formatting keeping longer calls manageable. Reading flow: Consistent formatting and method boundaries support sequential reading, but irrelevant checks repeatedly interrupt it, while descriptor-based assignments and backward-compatible state reconstruction require extra attention.

Run 2

Code Structure: Methods are logically organized around initialization, immutability, copying, and serialization, but slot-order dependencies and long positional constructor calls make maintenance harder. Nesting: Mostly shallow, with modest branching and readable loops; multiline conditional expressions add some complexity. Clarity of intent: Descriptive method names, documentation, and comments explain behavior, but repeated always-false hexadecimal XOR checks introduce distracting, purposeless logic. Code length: Extensive documentation is useful, while repetitive field assignments and dead assertion guards unnecessarily lengthen the implementation. Action granularity: Generally one action per line, with explicit assignments and well-separated operations. Reading flow: Consistent formatting and focused methods support natural reading, but opaque guards, lengthy argument lists, external helper dependencies, and awkward line wrapping interrupt it.

Run 3

Code Structure: Methods are logically grouped within a well-documented class, although slot-order dependencies and long positional constructor calls create fragility. Nesting: Mostly shallow, with modest branching in evolution and state restoration. Clarity of intent: Descriptive method names, comments, and docstrings explain immutability, metadata handling, and compatibility; repeated always-false hexadecimal assertions introduce confusing noise. Code length: Extensive documentation is useful, but redundant assertions and repetitive initialization make the implementation longer than necessary. Action granularity: Generally one action per line, with explicit assignments and clearly separated steps. Reading flow: Consistent formatting and focused methods support natural reading, but lengthy argument lists, multiline conditional expressions, and reliance on external helpers interrupt comprehension.