Sample

pyint-7b384563d721-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines131

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3770–1; higher is more readable
Mi0.6020–1; higher is more readable
LLOC56Logical lines; fewer is more readable
DeepSeek V4 Pro120–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.5240–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. """ first_score = 72 second_score = 85 if first_score > second_score: higher_score = first_score else: higher_score = second_score 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.2719.49−89.743
Source linesThe number of non-empty source lines.131+52.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.397−6.596

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.131−3.602
Indentation frequencyHow rapidly indentation changes from line to line.101+2.756
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.101−1.897
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.130.833+1.419
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.100.977+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.955−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.502 (log-odds).
Score = sigmoid(-0.502) = 0.377.

Score0.602
Score56
Run 1

The code is generally well-structured with clear docstrings, type hints, and logical organization into classes and methods. The Converter class has a clear purpose and its methods are mostly concise and focused. However, there are readability issues: the __init__ method uses lambda assignments with multiple underscores and conditional branching that makes the intent harder to follow at a glance. The _fmt_converter_call method has very long f-strings that exceed typical line-length expectations and mix logic with string formatting. The __setstate__ method contains dead code (unused score comparison) that adds confusion and suggests incomplete cleanup. Nesting is low, and most actions are granular, but the conditional lambda chains reduce clarity. Overall, the code is readable but suffers from some awkward constructs and dead code.

Run 2

The code has good structure with clear class, type hints, and docstrings, but the `Converter` class contains a confusing `__setstate__` method with unrelated scoring logic that severely damages clarity. The nested conditional lambdas in `__init__` reduce readability due to multiple layers of logic in one expression. The long conditional return in `_fmt_converter_call` is overly verbose and mixes formatting logic in a way that could be simplified. The action granularity is mostly one action per line, but the unrelated score comparison in `__setstate__` breaks intent. Imports are organized, and overall nesting is shallow. The impossible score comparison with hardcoded values implies a bug or leftover debug code, making the intent ambiguous and undermining trust in the code.

Run 3

The code is generally well-structured and readable. It follows clear organization with logical imports, a single class with a focused responsibility, and descriptive method names. The nesting is minimal, and most lines perform a single action. The intent of the Converter class and its methods is clearly documented with docstrings and type hints. However, there are a few minor issues: the else branch in __init__ assigns self.__call__ = self.converter without an explicit lambda wrapper, which could be slightly confusing; the _fmt_converter_call method contains long f-string lines that reduce readability; and the __setstate__ method contains an odd, unrelated block of code assigning first_score and second_score that appears to be a leftover or debug artifact, which disrupts the reading flow and clarity. Overall, the code is readable but would benefit from removing the unrelated block and slightly formatting long lines.

Run 1

1. Code Structure: Methods are logically grouped in a focused class, but unrelated score-comparison code in __setstate__ and many unused imports introduce clutter. 2. Nesting: Mostly flat conditionals and early returns make branching easy to follow. 3. Clarity of intent: Descriptive method names and detailed docstrings explain converter behavior, although abbreviated variables, placeholder lambda arguments, and dynamically assigned __call__ require extra attention. The __getstate__ docstring omits takes_field despite its inclusion in the returned state. 4. Code length: Generally concise, but unused imports, irrelevant statements, and repeated converter-name formatting add unnecessary length. 5. Action granularity: Statements generally perform one action per line; multiline lambdas remain reasonably readable. 6. Reading flow: Initialization, call formatting, and serialization form a natural progression, disrupted by the unrelated comparison block and long generated-call strings.

Run 2

Code Structure: Methods are logically grouped within a focused class, but numerous unused imports and unrelated score calculations in __setstate__ introduce clutter. Nesting: Control flow is shallow, with straightforward conditional branches. Clarity of intent: Descriptive method names and docstrings explain converter behavior, though abbreviated names such as ex and rt, placeholder lambda parameters, and dynamic __call__ assignment require extra interpretation. The __getstate__ docstring also omits takes_field despite its inclusion in the returned state. Code length: Mostly concise, but unused imports, redundant score calculations, and some lengthy generated-call strings reduce economy. Action granularity: Generally one action per line, with multiline expressions formatted clearly. Reading flow: Initialization, call formatting, and serialization form a natural progression, interrupted by irrelevant logic in __setstate__.

Run 3

Code Structure: Methods are logically grouped in a focused class, but numerous unused imports and unrelated score calculations in __setstate__ introduce clutter. Nesting: Control flow is shallow, with straightforward conditional branches. Clarity of intent: Descriptive method names and detailed docstrings explain converter behavior, though dynamic __call__ assignment requires care, and __getstate__ documentation incorrectly omits takes_field. Code length: Mostly concise, but repeated converter-call formatting, unused imports, and dead score logic add unnecessary length. Action granularity: Statements generally perform one action per line; multiline lambdas remain understandable. Reading flow: The class progresses naturally from initialization to call formatting and serialization, but abbreviated names such as ex and rt, long generated-call strings, and irrelevant serialization logic interrupt that flow.