Sample

pyint-b8a6026d5e12-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines125

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3910–1; higher is more readable
Mi0.6020–1; higher is more readable
LLOC51Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.6020–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.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.411−6.617

Intercept 8.87 + feature contributions = -32.23 (log-odds).
Score = sigmoid(-32.23) = 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.873+1.336
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.100.976+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.96−0.611
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.042+0.536

Intercept 0.07 + feature contributions = -0.444 (log-odds).
Score = sigmoid(-0.444) = 0.391.

Score0.602
Score51
Run 1

The code is well-structured and readable. It uses clear class design with slots, docstrings, and named parameters. The Converter class has a logical flow, and methods are concise with single responsibilities. Nesting is flat, intent is clear, and action granularity is appropriate. Minor issues include the lambda assignments in __init__ which slightly reduce clarity, and the long f-string lines in _fmt_converter_call could be reformatted for better readability.

Run 2

The code is well-structured with clear class-level organization, comprehensive docstrings, and logical method separation. Nesting is minimal, with only two levels of conditional branching in __init__ and _fmt_converter_call. Intent is clearly communicated through descriptive method names and detailed docstrings explaining parameters and behavior. Code length is appropriate - each method is focused and avoids unnecessary verbosity. Action granularity is good, with one clear operation per line in most cases. Reading flow is natural, following a logical progression from initialization to serialization methods. Minor deductions: the lambda assignments in __init__ create slightly dense logic, and the f-strings in _fmt_converter_call contain long lines with multiple embedded expressions that could benefit from intermediate variables for readability.

Run 3

The code is generally well-structured with clear docstrings, type hints, and consistent naming. The class has a logical organization: imports, class definition, slots, init, helper methods, and serialization. However, readability is slightly reduced by the conditional lambda assignments in __init__, which compress multiple actions and intent into a dense block. While the logic is understandable, the lambda expressions with placeholders (_, __) can be less clear to readers unfamiliar with the pattern. The _fmt_converter_call method has some long f-strings but remains readable. Nesting is flat and action granularity is mostly one line per action. Overall, it is maintainable and clear, but could benefit from slightly more explicit handling of the conditional callable assignment to improve clarity.

Run 1

Code Structure: The class is logically organized into initialization, naming, call formatting, and serialization methods, though the large import block contains many imports unused in this snippet. Nesting: Conditional branches remain shallow, and early returns keep call formatting flat. Clarity of intent: Descriptive method names and detailed docstrings explain the converter wrapper well. However, dynamic assignment to __call__, lambda placeholders, and abbreviated names such as ex and rt require extra interpretation. The __getstate__ docstring also omits takes_field despite its inclusion in the returned state. Code length: Methods are concise overall, although repeated flag checks and long formatted strings add some verbosity. Action granularity: Most lines perform one clear action; multiline lambda expressions remain reasonably readable. Reading flow: Methods follow a natural progression, with consistent formatting and useful documentation, but metaprogramming details and generated call strings modestly interrupt straightforward reading.

Run 2

Code Structure: The class is logically organized into initialization, call formatting, and serialization methods, with helpful documentation. Nesting: Control flow is shallow, using straightforward conditionals and early returns. Clarity of intent: Descriptive method and field names clarify converter behavior, although dynamic __call__ assignment, placeholder lambda parameters, and abbreviated names such as ex and rt require extra attention. The __getstate__ docstring also omits takes_field, unlike the implementation. Code length: Methods are reasonably concise, but repeated flag combinations and global-name formatting add some redundancy; many imports are unused in this excerpt. Action granularity: Statements generally perform one action per line, with readable multiline expressions. Reading flow: The progression is natural and consistent, though long generated-call strings and annotation manipulation slightly interrupt readability.

Run 3

Code Structure: The class is logically organized into initialization, call formatting, and serialization methods, although many imports are unused in this snippet. Nesting: Shallow conditionals and early returns keep control flow easy to follow. Clarity of intent: Descriptive method names and detailed docstrings explain the converter's purpose, but abbreviated variables such as ex and rt, placeholder lambda arguments, and dynamic __call__ assignment 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 flag checks and generated-call expressions add some duplication. Action granularity: Statements generally perform one action per line, with readable multiline formatting. Reading flow: The progression from configuration to invocation formatting and state persistence is natural; long f-strings and annotation manipulation slightly interrupt readability.