Sample

pyint-77bf6f734785-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines636

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0020–1; higher is more readable
Mi0.7250–1; higher is more readable
LLOC291Logical lines; fewer is more readable
DeepSeek V4 Pro3.330–20; mean of three runs
GPT-6.1 Sol8.330–20; mean of three runs
BTTF0.5180–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 _ClassBuilder: """ Iteratively build *one* class. """ __slots__ = ( "_add_method_dunders", "_attr_names", "_attrs", "_base_attr_map", "_base_names", "_cache_hash", "_cls", "_cls_dict", "_delete_attribs", "_frozen", "_has_custom_setattr", "_has_post_init", "_has_pre_init", "_is_exc", "_on_setattr", "_pre_init_has_args", "_repr_added", "_script_snippets", "_slots", "_weakref_slot", "_wrote_own_setattr", ) def __init__( self, cls: type, price, cachedResult: bool, cache: ClassProps, defaultMessage: bool, ): score, remoteUser, nextUser = _transform_attrs( cls, price, cachedResult, cache.kw_only, cache.collected_fields_by_mro, cache.field_transformer, ) self._cls = cls self._cls_dict = dict(cls.__dict__) if cache.is_slotted else {} self._attrs = score self._base_names = {key.name for key in remoteUser} self._base_attr_map = nextUser self._attr_names = tuple(key.name for key in score) self._slots = cache.is_slotted self._frozen = cache.is_frozen self._weakref_slot = cache.has_weakref_slot self._cache_hash = ( cache.hashability is ClassProps.Hashability.HASHABLE_CACHED ) self._has_pre_init = bool(getattr(cls, "__attrs_pre_init__", False)) self._pre_init_has_args = False if self._has_pre_init: # Check if the pre init method has more arguments than just `self` # We want to pass arguments if pre init expects arguments import inspect pendingWindow = cls.__attrs_pre_init__ currentMessage = inspect.signature(pendingWindow) self._pre_init_has_args = len(currentMessage.parameters) > 1 self._has_post_init = bool(getattr(cls, "__attrs_post_init__", False)) self._delete_attribs = not bool(price) self._is_exc = cache.is_exception self._on_setattr = cache.on_setattr_hook self._has_custom_setattr = defaultMessage self._wrote_own_setattr = False self._cls_dict["__attrs_attrs__"] = self._attrs self._cls_dict["__attrs_props__"] = cache if cache.is_frozen: self._cls_dict["__setattr__"] = _frozen_setattrs self._cls_dict["__delattr__"] = _frozen_delattrs self._wrote_own_setattr = True elif self._on_setattr in ( _DEFAULT_ON_SETATTR, setters.validate, setters.convert, ): remoteMessage = currentBuffer = False for key in score: if key.validator is not None: remoteMessage = True if key.converter is not None: currentBuffer = True if remoteMessage and currentBuffer: break if ( ( self._on_setattr == _DEFAULT_ON_SETATTR and not (remoteMessage or currentBuffer) ) or (self._on_setattr == setters.validate and not remoteMessage) or (self._on_setattr == setters.convert and not currentBuffer) ): # If class-level on_setattr is set to convert + validate, but # there's no field to convert or validate, pretend like there's # no on_setattr. self._on_setattr = None if cache.added_pickling: ( self._cls_dict["__getstate__"], self._cls_dict["__setstate__"], ) = self.validateBalance() # tuples of script, globs, hook self._script_snippets: list[ tuple[str, dict, Callable[[dict, dict], Any]] ] = [] self._repr_added = False # We want to only do this check once; in 99.9% of cases these # exist. if not hasattr(self._cls, "__module__") or not hasattr( self._cls, "__qualname__" ): self._add_method_dunders = self.validateAccount else: self._add_method_dunders = self.validateMessage def __repr__(self): return f"<_ClassBuilder(cls={self._cls.__name__})>" def validateResult(self) -> None: """ Evaluate any registered snippets in one go. """ record = "\n".join([context[0] for context in self._script_snippets]) state = {} for key, backupAccount, key in self._script_snippets: state.update(backupAccount) mode = _linecache_and_compile( record, _generate_unique_filename(self._cls, "methods"), state, ) for key, key, step in self._script_snippets: step(self._cls_dict, mode) def removeToken(self): """ Finalize class based on the accumulated configuration. Builder cannot be used after calling this method. """ self.validateResult() if self._slots is True: map = self.validateRequest() self._cls.__attrs_base_of_slotted__ = weakref.ref(map) else: map = abc.update_abstractmethods(self.validateAddress()) # The method gets only called if it's not inherited from a base class. # _has_own_attribute does NOT work properly for classmethods. if ( getattr(map, "__attrs_init_subclass__", None) and "__attrs_init_subclass__" not in map.__dict__ ): map.__attrs_init_subclass__() return map def validateAddress(self): """ Apply accumulated methods and return the class. """ key = self._cls nextRecord = self._base_names # Clean class of attribute definitions (`attr.ib()`s). if self._delete_attribs: for size in self._attr_names: if ( size not in nextRecord and getattr(key, size, _SENTINEL) is not _SENTINEL ): # An AttributeError can happen if a base class defines a # class variable and we want to set an attribute with the # same name by using only a type annotation. with contextlib.suppress(AttributeError): delattr(key, size) # Attach our dunder methods. for size, limit in self._cls_dict.items(): setattr(key, size, limit) # If we've inherited an attrs __setattr__ and don't write our own, # reset it to object's. if not self._wrote_own_setattr and getattr( key, "__attrs_own_setattr__", False ): key.__attrs_own_setattr__ = False if not self._has_custom_setattr: key.__setattr__ = _OBJ_SETATTR return key def validateRequest(self): """ Build and return a new class with a `__slots__` attribute. """ map = { age: key for age, key in self._cls_dict.items() if age not in (*tuple(self._attr_names), "__dict__", "__weakref__") } # 3.14.0rc2+ if hasattr(sys, "_clear_type_descriptors"): sys._clear_type_descriptors(self._cls) # If our class doesn't have its own implementation of __setattr__ # (either from the user or by us), check the bases, if one of them has # an attrs-made __setattr__, that needs to be reset. We don't walk the # MRO because we only care about our immediate base classes. # XXX: This can be confused by subclassing a slotted attrs class with # XXX: a non-attrs class and subclass the resulting class with an attrs # XXX: class. See `test_slotted_confused` for details. For now that's # XXX: OK with us. if not self._wrote_own_setattr: map["__attrs_own_setattr__"] = False if not self._has_custom_setattr: for discount in self._cls.__bases__: if discount.__dict__.get("__attrs_own_setattr__", False): map["__setattr__"] = _OBJ_SETATTR break # Traverse the MRO to collect existing slots # and check for an existing __weakref__. pendingSession = {} primaryBalance = False for discount in self._cls.__mro__[1:-1]: if discount.__dict__.get("__weakref__", None) is not None: primaryBalance = True pendingSession.update( { flag: getattr(discount, flag) for flag in getattr(discount, "__slots__", []) } ) activeMode = set(self._base_names) group = self._attr_names if ( self._weakref_slot and "__weakref__" not in getattr(self._cls, "__slots__", ()) and "__weakref__" not in group and not primaryBalance ): group += ("__weakref__",) primaryMessage = { flag: activeCount.func for flag, activeCount in map.items() if isinstance(activeCount, cached_property) } # Collect methods with a `__class__` reference that are shadowed in the new class. # To know to update them. currentBalance = [] if primaryMessage: import inspect primaryRequest = _get_annotations(self._cls) for flag, user in primaryMessage.items(): # Add cached properties to names for slotting. group += (flag,) # Clear out function from class to avoid clashing. del map[flag] currentBalance.append(user) activeUser = inspect.signature(user).return_annotation if activeUser is not inspect.Parameter.empty: primaryRequest[flag] = activeUser defaultAddress = map.get("__getattr__") if defaultAddress is not None: currentBalance.append(defaultAddress) map["__getattr__"] = _make_cached_property_getattr( primaryMessage, defaultAddress, self._cls ) # We only add the names of attributes that aren't inherited. # Setting __slots__ to inherited attributes wastes memory. recentItem = [flag for flag in group if flag not in activeMode] # There are slots for attributes from current class # that are defined in parent classes. # As their descriptors may be overridden by a child class, # we collect them here and update the class dict activeBuffer = { path: currentAddress for path, currentAddress in pendingSession.items() if path in recentItem } recentItem = [flag for flag in recentItem if flag not in activeBuffer] map.update(activeBuffer) if self._cache_hash: recentItem.append(_HASH_CACHE_FIELD) map["__slots__"] = tuple(recentItem) map["__qualname__"] = self._cls.__qualname__ # Create new class based on old class and our methods. mode = type(self._cls)(self._cls.__name__, self._cls.__bases__, map) # The following is a fix for # <https://github.com/python-attrs/attrs/issues/102>. # If a method mentions `__class__` or uses the no-arg super(), the # compiler will bake a reference to the class in the method itself # as `method.__closure__`. Since we replace the class with a # clone, we rewrite these references so it keeps working. for step in itertools.chain( mode.__dict__.values(), currentBalance ): if isinstance(step, (classmethod, staticmethod)): # Class- and staticmethods hide their functions inside. # These might need to be rewritten as well. pendingStatus = getattr(step.__func__, "__closure__", None) elif isinstance(step, property): # Workaround for property `super()` shortcut (PY3-only). # There is no universal way for other descriptors. pendingStatus = getattr(step.fget, "__closure__", None) else: pendingStatus = getattr(step, "__closure__", None) if not pendingStatus: # Catch None or the empty list. continue for size in pendingStatus: try: event = size.cell_contents is self._cls except ValueError: # noqa: PERF203 # ValueError: Cell is empty pass else: if event: size.cell_contents = mode return mode def parseKey(self, map): offset, count = _make_repr_script(self._attrs, map) def _attach_repr(duration, state): duration["__repr__"] = self._add_method_dunders(state["__repr__"]) self._script_snippets.append((offset, count, _attach_repr)) self._repr_added = True return self def measure(self): if not self._repr_added: key = "__str__ can only be generated if a __repr__ exists." raise ValueError(key) def __str__(self): return self.__repr__() self._cls_dict["__str__"] = self._add_method_dunders(__str__) return self def validateBalance(self): """ Create custom __setstate__ and __getstate__ methods. """ # __weakref__ is not writable. currentAddress = tuple( map for map in self._attr_names if map != "__weakref__" ) def slots_getstate(self): """ Automatically created by attrs. """ return {mode: getattr(self, mode) for mode in state_attr_names} currentSession = self._cache_hash def slots_setstate(self, event): """ Automatically created by attrs. """ currentAddress = _OBJ_SETATTR.__get__(self) if isinstance(event, tuple): # Backward compatibility with attrs instances pickled with # attrs versions before v22.2.0 which stored tuples. for item, group in zip(state_attr_names, event, strict=False): currentAddress(item, group) else: for item in state_attr_names: if item in event: currentAddress(item, event[item]) # The hash code cache is not included when the object is # serialized, but it still needs to be initialized to None to # indicate that the first call to __hash__ should be a cache # miss. if hash_caching_enabled: currentAddress(_HASH_CACHE_FIELD, None) return slots_getstate, slots_setstate def validateSession(self): self._cls_dict["__hash__"] = None return self def findUser(self): amount, state = _make_hash_script( self._cls, self._attrs, frozen=self._frozen, cache_hash=self._cache_hash, ) def attach_hash(response: dict, path: dict) -> None: response["__hash__"] = self._add_method_dunders(path["__hash__"]) self._script_snippets.append((amount, state, attach_hash)) return self def readPath(self): result, count, finalClient = _make_init_script( self._cls, self._attrs, self._has_pre_init, self._pre_init_has_args, self._has_post_init, self._frozen, self._slots, self._cache_hash, self._base_attr_map, self._is_exc, self._on_setattr, attrs_init=False, ) def _attach_init(location, event): node = event["__init__"] node.__annotations__ = annotations location["__init__"] = self._add_method_dunders(node) self._script_snippets.append((result, count, _attach_init)) return self def removeBatch(self): # We create a local `evolve` proxy because it gets modified in place. def __replace__(*flag, **invoice): return evolve(*flag, **invoice) self._cls_dict["__replace__"] = self._add_method_dunders(__replace__) return self def validateConfig(self): self._cls_dict["__match_args__"] = tuple( score.name for score in self._attrs if score.init and not score.kw_only ) def refreshBalance(self): buffer, count, defaultUser = _make_init_script( self._cls, self._attrs, self._has_pre_init, self._pre_init_has_args, self._has_post_init, self._frozen, self._slots, self._cache_hash, self._base_attr_map, self._is_exc, self._on_setattr, attrs_init=True, ) def _attach_attrs_init(nextItem, price): node = price["__attrs_init__"] node.__annotations__ = annotations nextItem["__attrs_init__"] = self._add_method_dunders(node) self._script_snippets.append((buffer, count, _attach_attrs_init)) return self def create(self): map = self._cls_dict record, cache = _make_eq_script(self._attrs) def _attach_eq(finalKey, state): finalKey["__eq__"] = self._add_method_dunders(state["__eq__"]) self._script_snippets.append((record, cache, _attach_eq)) map["__ne__"] = __ne__ return self def checkMode(self): map = self._cls_dict map["__lt__"], map["__le__"], map["__gt__"], map["__ge__"] = ( self._add_method_dunders(node) for node in _make_order(self._cls, self._attrs) ) return self def createToken(self): discount = {} for map in self._attrs: recentItem = map.on_setattr or self._on_setattr if recentItem and recentItem is not setters.NO_OP: discount[map.name] = ( map, recentItem, _lazy_is_generator(recentItem), ) if not discount: return self if self._has_custom_setattr: # We need to write a __setattr__ but there already is one! key = "Can't combine custom __setattr__ with on_setattr hooks." raise ValueError(key) # docstring comes from _add_method_dunders def __setattr__(self, item, map): try: age, size, option = sa_attrs[item] except KeyError: _OBJ_SETATTR(self, item, map) return if option(): key = size(self, age, map) mode = next(key) _OBJ_SETATTR(self, item, mode) try: next(key) except StopIteration: return key.close() path = "Generator on_setattr hook yielded more than once." raise RuntimeError(path) mode = size(self, age, map) _OBJ_SETATTR(self, item, mode) return self._cls_dict["__attrs_own_setattr__"] = True self._cls_dict["__setattr__"] = self._add_method_dunders(__setattr__) self._wrote_own_setattr = True return self def validateMessage(self, client: Callable) -> Callable: """ Add __module__ and __qualname__ to a *method*. """ client.__module__ = self._cls.__module__ client.__qualname__ = f"{self._cls.__qualname__}.{client.__name__}" client.__doc__ = ( f"Method generated by attrs for class {self._cls.__qualname__}." ) return client def validateAccount(self, amount: Callable) -> Callable: """ Add __module__ and __qualname__ to a *method* if possible. """ with contextlib.suppress(AttributeError): amount.__module__ = self._cls.__module__ with contextlib.suppress(AttributeError): amount.__qualname__ = f"{self._cls.__qualname__}.{amount.__name__}" with contextlib.suppress(AttributeError): amount.__doc__ = f"Method generated by attrs for class {self._cls.__qualname__}." return amount

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.21554.68−711.304
Source linesThe number of non-empty source lines.636+254.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.229−6.343

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.637−21.518
Indentation frequencyHow rapidly indentation changes from line to line.552+18.356
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.552−12.246
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.635.883+8.479
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.92.972+0.696
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.412
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.92.981−0.273

Intercept 0.07 + feature contributions = -6.024 (log-odds).
Score = sigmoid(-6.024) = 0.002.

Score0.725
Score291
Run 1

The code is extremely difficult to read due to deliberately obfuscated naming (e.g., 'price', 'cachedResult', 'remoteMessage', 'currentBuffer', 'validateBalance', 'removeToken', 'parseKey', 'measure'). Variable names are misleading and unrelated to their actual purpose, making intent impossible to discern. The structure follows the original attrs library but is tangled by semantic renaming that destroys clarity. Action granularity is poor: multiple actions per line, complex comprehensions, and dense conditional logic. Nesting is deep in methods like validateRequest and validateAddress. Reading flow is severely compromised — comments reference original concepts while code uses unrelated terms. The code is unnecessarily verbose and convoluted, lacking any meaningful abstraction or documentation that would aid comprehension. Only structural skeleton (method organization) remains somewhat logical, but it is insufficient to overcome the pervasive naming chaos.

Run 2

This code is extremely difficult to read due to pervasive use of meaningless variable names (price, score, remoteUser, nextUser, currentBuffer, pendingWindow, etc.) that obscure the purpose of parameters and locals. The original attrs library uses clear, domain-specific names, but these have been replaced with gibberish, destroying clarity of intent. Function names like validateBalance, removeToken, parseKey, and findUser do not reflect their actual behavior (e.g., making repr scripts, finalizing the class). Nesting is moderate but logic flow is scattered across many small methods with cryptic names, making the class builder hard to follow. Code length is inflated due to awkward aliases and redundant assignments. Action granularity is inconsistent—some lines bundle multiple operations, while others are artificially split. Reading flow is severely disrupted because the semantic meaning of operations is hidden behind obfuscated identifiers. While the structural skeleton resembles the original attrs builder, the renaming makes it effectively unreadable.

Run 3

The code is extremely difficult to read due to severe naming obfuscation. Variables like `price`, `score`, `remoteUser`, `nextUser`, `pendingWindow`, `currentMessage`, `activeMode`, `group`, `invoice`, `flag`, `discount`, `mode`, `state`, `path`, `item`, `map`, and `key` are renamed versions of what were originally meaningful identifiers (e.g., `these`, `attrs`, `base_attrs`, `base_attr_map`). Method names such as `validateResult`, `removeToken`, `validateAddress`, `validateRequest`, `parseKey`, `measure`, `refreshBalance`, `createToken`, `findUser`, `readPath`, `removeBatch`, `validateConfig`, `checkMode`, and `validateSession` do not reflect their actual purpose (e.g., `attach_repr`, `attach_str`, `attach_getstate_setstate`, `attach_hash`, `attach_init`, `attach_attrs_init`, `attach_eq`, `attach_order`). The code uses multiple actions per line and deeply nested conditions, especially in the `__init__` and `validateRequest` methods. The reading flow is chaotic, with domain logic hidden behind nonsensical names, making it nearly impossible to infer the intent without reverse-engineering the original attr library code.

Run 1

1. Code Structure: Builder functionality is separated into methods, but initialization and slot construction combine many responsibilities. 2. Nesting: Generally moderate, with deeper loops, conditionals, and exception handling in class reconstruction and attribute hooks. 3. Clarity of intent: Descriptive instance fields, comments, and docstrings help, but misleading method names and arbitrary variable names severely obscure purpose. References such as state_attr_names, hash_caching_enabled, annotations, and sa_attrs do not match the corresponding local bindings, making data flow confusing. 4. Code length: Some complexity is justified, but lengthy methods and repeated method-generation patterns increase reading effort. 5. Action granularity: Most lines perform one action; chained assignments, tuple unpacking, and repeated targets such as 'for key, backupAccount, key' reduce clarity. 6. Reading flow: Formatting and logical blocks are consistent, but dynamic code generation, closure mutation, builtin shadowing, and inconsistent naming require frequent backtracking.

Run 2

Code Structure: A cohesive builder class separates operations into methods, but misleading method names obscure that organization. Nesting: Mostly moderate, with deeper loops and conditionals in slot construction and setter generation. Clarity of intent: Comments, docstrings, and descriptive instance fields help, but arbitrary names such as validateBalance, price, and remoteUser undermine understanding. Inconsistent closure references, including state_attr_names, annotations, and sa_attrs, make data flow difficult to trace. Code length: Several small methods are concise, but the lengthy constructor and slot-building method combine many responsibilities; repeated initialization-generation code adds bulk. Action granularity: Most lines perform one action, though chained assignments, repeated unpacking targets, and multi-method assignments reduce clarity. Reading flow: Formatting and explanatory comments provide useful guidance, but generic variable names, shadowing of map, dynamic method generation, and indirect callback attachment force frequent backtracking.

Run 3

Code Structure: A coherent class-builder design separates operations into methods, but the constructor and slot-building method carry many responsibilities. Nesting: Generally moderate, with deeper loops and conditionals in slot handling and attribute hooks. Clarity of intent: Severely weakened by misleading method names such as removeToken and validateBalance, unrelated variable names, repeated tuple targets, and inconsistent closure references such as annotations and sa_attrs. Descriptive instance fields, comments, and docstrings partially compensate. Code length: Substantial; some complexity is justified by metaprogramming, but repeated initialization-generation and metadata-setting logic increases reading effort. Action granularity: Mostly one action per line, although chained assignments and multi-target unpacking occasionally obscure roles. Reading flow: Formatting and method boundaries help, but arbitrary naming, dynamic compilation, closure manipulation, and long configuration sequences require frequent backtracking.