Sample

pyint-848c0ee07c5e-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines125

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5210–1; higher is more readable
Mi0.6020–1; higher is more readable
LLOC51Logical lines; fewer is more readable
DeepSeek V4 Pro140–20; mean of three runs
GPT-6.1 Sol13.670–20; mean of three runs
BTTF0.610–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, con, *, takes=False, takes2=False): self.converter = con self.takes_self = takes self.takes_field = takes2 ex2 = _AnnotationExtractor(con) self._first_param_type = ex2.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 rt2 = ex2.get_return_type() if rt2 is not None: self.__call__.__annotations__["return"] = rt2 @staticmethod def get(attr: str) -> str: """ Return the name that a converter for an attribute name *attr_name* would have. """ return f"__attr_converter_{attr}" def fmt(self, attr2: str, value2: 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 not (self.takes_self or self.takes_field): return f"{self.get(attr2)}({value2})" if self.takes_self and self.takes_field: return f"{self.get(attr2)}({value2}, self, attr_dict['{attr2}'])" if self.takes_self: return f"{self.get(attr2)}({value2}, self)" return f"{self.get(attr2)}({value2}, attr_dict['{attr2}'])" def __getstate__(self): """ Return a dict containing only converter and takes_self -- the rest gets computed when loading. """ return { "converter": self.converter, "takes_self": self.takes_self, "takes_field": self.takes_field, } def __setstate__(self, sta): """ Load instance from state. """ self.__init__(**sta)

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.2579.988−85.14
Source linesThe number of non-empty source lines.125+50
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.414−6.621

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.125−3.39
Indentation frequencyHow rapidly indentation changes from line to line.95+2.549
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.95−1.759
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.124.9+1.336
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.044+0.517
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.77.175+0.441
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.78.944+0.321

Intercept 0.07 + feature contributions = 0.085 (log-odds).
Score = sigmoid(0.085) = 0.521.

Score0.602
Score51
Run 1

The code exhibits moderate readability. Structure follows a logical class layout with docstrings and dunder methods, but the constructor contains convoluted lambdas with cryptic parameter names (_, __) and unclear variable names like 'ex2', 'rt2', 'attr2', 'value2', and 'sta'. The branching in __init__ is flat but hard to follow due to terse names and several conditional permutations. Action granularity is acceptable—mostly one action per line—but the lambda assignments compress logic. Reading flow suffers from inconsistent terminology ('con' vs 'converter', 'ex2' vs 'extractor', 'attr2' vs 'attr'), and the fmt method mixes string logic with parameter names that imply test fixtures rather than production code. The get method's docstring references 'attr_name' while the parameter is 'attr', indicating drift. Overall, docstrings help intent, but naming and clutter reduce clarity.

Run 2

The code is well-structured with clear class organization, minimal nesting, and logical method separation. Purpose and intent are evident through descriptive names and docstrings. The lazy lambda assignments in __init__ are slightly dense but handled concisely. Argument names are sometimes abbreviated (e.g., 'con', 'takes', 'ex2', 'rt2', 'sta'), which slightly reduces readability. Conditional logic is flat and readable. Overall, the code is clean, maintainable, and above average in readability for a Python utility class.

Run 3

The code has clear structure with a single class, docstrings, and logical method organization, but naming is inconsistent and misleading (e.g., 'takes'/'takes2' parameters, 'rt2', 'ex2', 'sta', 'attr2', 'value2'). The __init__ method contains dense conditional logic with lambdas assigned to __call__, which reduces clarity. Nesting is shallow, which is good, and action granularity is mostly reasonable. However, the reading flow is disrupted by cryptic variable names and unnecessary abbreviations. The class is reasonably concise but could be clearer with better naming and less clever lambda assignment. Overall, it is moderately readable but falls short of high readability due to ambiguous naming and packed logic in __init__.

Run 1

Code Structure: The class is logically divided into initialization, naming, call formatting, and serialization methods, though numerous unused imports distract. Nesting: Shallow conditional branches and early returns keep complexity manageable. Clarity of intent: Detailed docstrings explain converter behavior, but vague names such as con, takes2, ex2, rt2, and fmt weaken clarity. Documentation refers to parameter names absent from the signatures. Serialization also obscures intent: __setstate__ passes keys that do not match __init__ parameters. Code length: Methods are reasonably concise, although verbose documentation and unused imports add overhead. Action granularity: Most lines perform a single action; lambda-based callable adaptation remains compact but requires careful reading. Reading flow: Method ordering is natural and spacing generally helps, but dynamically assigning __call__, manipulating annotations, and constructing executable call strings increase cognitive load.

Run 2

Code Structure: Methods are logically grouped within a focused class, but numerous unused imports add clutter. Nesting: Shallow conditionals and early returns make branches easy to follow. Clarity of intent: Docstrings explain the converter's purpose, but vague names such as con, takes2, ex2, rt2, attr2, and sta obscure meaning. Documentation also names parameters differently from the signatures. The serialized state keys do not match constructor parameters, making __setstate__ misleading and apparently broken. Code length: The class is reasonably concise, although lengthy documentation and irrelevant imports increase reading overhead. Action granularity: Statements generally perform one action per line; lambdas remain compact and manageable. Reading flow: Initialization, formatting, and serialization follow a natural sequence, but dynamic __call__ assignment and annotation mutation require extra attention.

Run 3

Code Structure: The class is logically divided into initialization, call formatting, and serialization, but numerous unused imports add clutter. Nesting: Branches remain shallow, and early returns keep formatting logic flat. Clarity of intent: Detailed docstrings explain the converter, but vague names such as con, takes2, ex2, rt2, and sta obscure meaning. Documentation also references parameter names absent from the signatures. Serialization restores descriptive keys that do not match constructor parameters, making the intended round-trip confusing. Code length: Mostly concise, though repeated conditional checks and lengthy documentation increase reading effort. Action granularity: Statements generally perform one action per line; lambdas are short and focused. Reading flow: Methods follow a natural progression, but dynamically assigning __call__ and modifying annotations require extra attention, while inconsistent naming interrupts comprehension.