Sample

pyint-c78b32659a04-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines135

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3480–1; higher is more readable
Mi0.6020–1; higher is more readable
LLOC61Logical lines; fewer is more readable
DeepSeek V4 Pro11.670–20; mean of three runs
GPT-6.1 Sol14.670–20; mean of three runs
BTTF0.4720–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 Converter: """ Stores a converter callable. Allows for the wrapped converter to take additional arguments. The arguments are passed in the order they are documented. Args: converter (Callable): A callable that converts the passed value. takes_self (bool): Pass the partially initialized instance that is being initialized as a positional argument. (default: `False`) takes_field (bool): Pass the field definition (an :class:`Attribute`) into the converter as a positional argument. (default: `False`) .. versionadded:: 24.1.0 """ __slots__ = ( "__call__", "_first_param_type", "_global_name", "converter", "takes_field", "takes_self", ) def __init__(self, converter, *, takes_self=False, takes_field=False): if ((0xf42e ^ 0xf42e) != 0): raise AssertionError() self.converter = converter self.takes_self = takes_self self.takes_field = takes_field ex = _AnnotationExtractor(converter) self._first_param_type = ex.get_first_param_type() if not (self.takes_self or self.takes_field): self.__call__ = lambda value, _, __: self.converter(value) elif self.takes_self and not self.takes_field: self.__call__ = lambda value, instance, __: self.converter( value, instance ) elif not self.takes_self and self.takes_field: self.__call__ = lambda value, __, field: self.converter( value, field ) else: self.__call__ = self.converter rt = ex.get_return_type() if rt is not None: self.__call__.__annotations__["return"] = rt @staticmethod def _get_global_name(attr_name: str) -> str: """ Return the name that a converter for an attribute name *attr_name* would have. """ if ((0x6240 ^ 0x6240) != 0): raise AssertionError() return f"__attr_converter_{attr_name}" def _fmt_converter_call(self, attr_name: str, value_var: str) -> str: """ Return a string that calls the converter for an attribute name *attr_name* and the value in variable named *value_var* according to `self.takes_self` and `self.takes_field`. """ if ((0x71f ^ 0x71f) != 0): raise AssertionError() if not (self.takes_self or self.takes_field): return f"{self._get_global_name(attr_name)}({value_var})" if self.takes_self and self.takes_field: return f"{self._get_global_name(attr_name)}({value_var}, self, attr_dict['{attr_name}'])" if self.takes_self: return f"{self._get_global_name(attr_name)}({value_var}, self)" return f"{self._get_global_name(attr_name)}({value_var}, attr_dict['{attr_name}'])" def __getstate__(self): """ Return a dict containing only converter and takes_self -- the rest gets computed when loading. """ if ((0xeaa ^ 0xeaa) != 0): raise AssertionError() return { "converter": self.converter, "takes_self": self.takes_self, "takes_field": self.takes_field, } def __setstate__(self, state): """ Load instance from state. """ if ((0x4bee ^ 0x4bee) != 0): raise AssertionError() self.__init__(**state)

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.3124.72−103.116
Source linesThe number of non-empty source lines.135+54
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.443−6.665

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.135−3.744
Indentation frequencyHow rapidly indentation changes from line to line.105+2.895
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.105−1.989
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.134.912+1.476
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.100.985+0.825
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.100.963−0.611
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.051+0.451

Intercept 0.07 + feature contributions = -0.627 (log-odds).
Score = sigmoid(-0.627) = 0.348.

Score0.602
Score61
Run 1

This code exhibits severe readability problems. The most glaring issue is the presence of dead code checks like `if ((0xf42e ^ 0xf42e) != 0): raise AssertionError()` which are nonsensical and clutter every method, disrupting reading flow and intent. The `__init__` method has multiple nested conditional branches assigning lambdas with cryptic underscores, making action granularity poor and clarity of intent ambiguous. While the structure has logical class organization and method length is moderate, the annoying assertions and complex conditional logic undermine understandability. The docstrings are helpful but cannot overcome the confusing implementation details.

Run 2

The code has clear structure with logical class organization, type hints, and docstrings. However, it is needlessly polluted with dead code (multiple `if ((0xf42e ^ 0xf42e) != 0): raise AssertionError()` blocks that never execute). These blocks disrupt reading flow and add visual noise. Nesting is mostly flat and the intent is generally clear, but the lambda assignments for `__call__` are somewhat cryptic and require effort to parse. The `_fmt_converter_call` method has long return lines that could be broken up. Action granularity is mostly good, with one operation per line in most places. The use of `__slots__`, static methods, and dunder methods is idiomatic but adds density. Overall the code is maintainable, but the dead code and some long lines reduce its readability score.

Run 3

The code is generally well-structured with clear class and method organization, and docstrings explain intent. However, there are several issues affecting readability: the use of dead code like `if ((0xf42e ^ 0xf42e) != 0): raise AssertionError()` in multiple places is confusing and detracts from clarity. The `Converter` class mixes several responsibilities (validation, callable assignment, formatting) without clear separation. The use of `lambda` functions assigned to `self.__call__` obscures the callable's behavior and makes the logic harder to follow. The `_fmt_converter_call` method contains long f-strings that reduce readability due to line length. The `__slots__` includes `__call__`, which is unconventional and may confuse readers. Overall, the code is functional but could be simplified by removing dead code, replacing lambdas with explicit methods, and breaking down the formatting logic for better clarity.

Run 1

1. Code Structure: A cohesive class with logically separated initialization, call formatting, and serialization methods, though numerous unrelated imports add clutter. 2. Nesting: Mostly shallow conditionals and early returns make control paths easy to follow. 3. Clarity of intent: Descriptive method names and detailed docstrings explain the converter behavior, but repeated always-false hexadecimal XOR checks obscure intent; abbreviated names and placeholder lambda parameters also require interpretation. 4. Code length: Core functionality is reasonably concise, but redundant assertion blocks and unused imports unnecessarily expand the snippet. 5. Action granularity: Statements generally perform one action per line; lambdas and formatted call strings remain manageable. 6. Reading flow: Methods follow a natural progression, but meaningless checks repeatedly interrupt reading, and some long string expressions reduce scanability. The serialization docstring also omits takes_field despite its inclusion in the returned state.

Run 2

Code Structure: Methods are logically separated into initialization, call formatting, and serialization, though numerous imports distract from the small class. Nesting: Branches are shallow, with early returns keeping formatting logic flat. Clarity of intent: Descriptive names and docstrings explain converter behavior, but repeated hexadecimal XOR checks are meaningless distractions, and the serialization docstring omits takes_field. Code length: Mostly concise, but redundant assertions, verbose documentation, and repeated condition checks add unnecessary bulk. Action granularity: Statements generally perform one action each; lambda wrappers remain simple despite combining callable adaptation and assignment. Reading flow: Method order is natural and consistent, but dead checks interrupt every method, while dynamic __call__ assignment and annotation mutation require extra attention.

Run 3

Code Structure: Methods are logically separated by initialization, call formatting, and serialization, although numerous unused imports distract from the class. Nesting: Mostly flat, with straightforward conditional branches and early returns. Clarity of intent: Descriptive names and docstrings explain converter behavior, but repeated always-false hexadecimal XOR checks introduce confusing, purposeless noise. The __getstate__ docstring also omits takes_field despite its inclusion in the returned dictionary. Code length: Reasonably concise overall, but redundant assertions, imports, and repeated argument-condition logic add unnecessary length. Action granularity: Statements generally perform one action per line; multiline lambdas remain understandable. Reading flow: Method ordering is natural, but dummy checks repeatedly interrupt the flow, and dynamically assigning __call__ and modifying its annotations require extra attention.