Sample

pyint-4c3b58458c6f-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines107

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4360–1; higher is more readable
Mi0.6570–1; higher is more readable
LLOC51Logical lines; fewer is more readable
DeepSeek V4 Pro90–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.5930–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): 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. """ 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 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. """ return { "converter": self.converter, "takes_self": self.takes_self, "takes_field": self.takes_field, } def __setstate__(self, state): """ Load instance from state. """ 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.2560.102−84.483
Source linesThe number of non-empty source lines.107+42.8
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.402−6.603

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.107−2.752
Indentation frequencyHow rapidly indentation changes from line to line.78+1.961
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.78−1.369
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.106.843+1.084
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.100.981+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.954−0.611
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.042+0.537

Intercept 0.07 + feature contributions = -0.256 (log-odds).
Score = sigmoid(-0.256) = 0.436.

Score0.657
Score51
Run 1

The code has some positive aspects, such as type annotations and a docstring for the class, but it suffers from severe readability issues. The import block is disorganized with inconsistent spacing and alignment, making it difficult to scan. Several lines cram multiple statements together (e.g., in __getstate__ and __init__), violating the one-action-per-line principle. The lambda assignments in __init__ are densely packed and hard to follow, with awkward line breaks and trailing spaces. Nesting is not deeply problematic, but the if/elif chain combined with lambdas reduces clarity. Code length is acceptable, but the lack of consistent formatting, coupled with cramped expressions and inconsistent indentation in places, significantly impairs natural reading flow. Overall, the code is functional but far from readable, requiring significant reformatting to improve comprehension.

Run 2

The code is functionally organized but suffers from poor readability due to inconsistent formatting and excessive nesting. The `Converter.__init__` method uses deeply nested conditional logic with lambda assignments, making the intent hard to follow. There are multiple actions packed into single lines (e.g., lambda definitions and assignment), violating the 'one action per line' principle. Import statements are irregularly aligned, and line breaks are inconsistent. The class docstring is clear, but `__init__` lacks a docstring and mixes type checking, attribute assignment, and conditional lambdas without separation. The reading flow is disrupted by awkward line wrapping and indentation. While the code is concise in places, this conciseness often comes at the cost of clarity. The structure would benefit from extracting helper methods and simplifying the branching logic to reduce cognitive load.

Run 3

The code has a clear class structure with a single Converter class and reasonable method separation, but suffers from several readability issues. Import formatting is inconsistent with awkward line breaks and spacing. The __init__ method has a deep nested conditional structure with four branches, making the logic harder to follow. Lambda assignments with positional parameters like `lambda value, _, __` obscure intent rather than clarifying it. Some lines are unnecessarily long (e.g., the _fmt_converter_call return statements exceeding 100 characters), while others are oddly broken. Formatting inconsistencies appear throughout—varying indentation, trailing spaces, and inconsistent line breaks in getstate returns. The docstrings are helpful and well-written, improving clarity of intent. Action granularity is mostly one action per line, but some lines combine multiple operations. Overall, the code is understandable but would benefit from cleaner formatting, extracted helper methods, and more descriptive variable names to improve readability.

Run 1

Code Structure: The class is logically organized into initialization, call formatting, and serialization methods, but inconsistent spacing and limited separation between methods weaken presentation. Nesting: Conditional logic stays shallow and is easy to follow. Clarity of intent: Descriptive method names and detailed docstrings explain converter behavior, although placeholder lambda parameters are cryptic and the serialization docstring omits takes_field. Code length: The implementation is reasonably concise, with some repetitive conditional checks and long formatted strings. Action granularity: Most executable lines perform one action, but crowded imports and dictionary entries reduce visual clarity. Reading flow: Methods follow a natural progression, yet irregular indentation, awkward closing parentheses, and long lines interrupt scanning.

Run 2

Code Structure: The class is logically organized into initialization, call formatting, and serialization methods, but inconsistent import formatting and missing spacing between methods weaken organization. Nesting: Control flow is shallow, with straightforward conditional branches and early returns. Clarity of intent: Descriptive method names and detailed docstrings explain the converter behavior, though placeholder lambda parameters and the abbreviated variable 'ex' require interpretation. The serialization docstring also omits takes_field. Code length: The implementation is reasonably concise, although repeated flag checks and generated-call expressions introduce some repetition. Action granularity: Most statements perform one action per line, but crowded imports and dictionary entries reduce visual separation. Reading flow: Methods follow a natural progression, but irregular whitespace, awkward closing parentheses, and long formatted strings interrupt scanning.

Run 3

Code Structure: The class is logically organized into initialization, call formatting, and serialization methods, but inconsistent spacing and crowded imports weaken presentation. Nesting: Conditional logic remains shallow, with straightforward branches and early returns. Clarity of intent: Descriptive method names and detailed docstrings explain converter behavior, although placeholder lambda arguments and dynamically assigned __call__ require extra interpretation. The __getstate__ docstring also omits takes_field despite its inclusion in the returned state. Code length: Methods are reasonably concise, though repeated converter-call strings and numerous imports unused in this snippet add clutter. Action granularity: Most statements perform one action per line, but multiple imports and dictionary entries share lines awkwardly. Reading flow: Method order is natural, but missing blank lines between methods, irregular indentation within continuations, and excessive inline whitespace interrupt scanning.