Sample

pyint-d8f7a9429937-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines104

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7920–1; higher is more readable
Mi0.2240–1; higher is more readable
LLOC40Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5940–1; higher is more readable

Views

Source code

from __future__ import annotations import dataclasses import decimal import json import typing as t import uuid import weakref from datetime import date from werkzeug.http import http_date class DefaultJSONProvider(JSONProvider): """Provide JSON operations using Python's built-in :mod:`json` library. Serializes the following additional data types: - :class:`datetime.datetime` and :class:`datetime.date` are serialized to :rfc:`822` strings. This is the same as the HTTP date format. - :class:`uuid.UUID` is serialized to a string. - :class:`dataclasses.dataclass` is passed to :func:`dataclasses.asdict`. - :class:`~markupsafe.Markup` (or any object with a ``__html__`` method) will call the ``__html__`` method to get a string. """ default: t.Callable[[t.Any], t.Any] = staticmethod(_default) """Apply this function to any object that :meth:`json.dumps` does not know how to serialize. It should return a valid JSON type or raise a ``TypeError``. """ ensure_ascii = True """Replace non-ASCII characters with escape sequences. This may be more compatible with some clients, but can be disabled for better performance and size. """ sort_keys = True """Sort the keys in any serialized dicts. This may be useful for some caching situations, but can be disabled for better performance. When enabled, keys must all be strings, they are not converted before sorting. """ compact: bool | None = None """If ``True``, or ``None`` out of debug mode, the :meth:`response` output will not add indentation, newlines, or spaces. If ``False``, or ``None`` in debug mode, it will use a non-compact representation. """ mimetype = "application/json" """The mimetype set in :meth:`response`.""" def dumps(self, obj: t.Any, **kwargs: t.Any) -> str: """Serialize data as JSON to a string. Keyword arguments are passed to :func:`json.dumps`. Sets some parameter defaults from the :attr:`default`, :attr:`ensure_ascii`, and :attr:`sort_keys` attributes. :param obj: The data to serialize. :param kwargs: Passed to :func:`json.dumps`. """ kwargs.setdefault("default", self.default) kwargs.setdefault("ensure_ascii", self.ensure_ascii) kwargs.setdefault("sort_keys", self.sort_keys) return json.dumps(obj, **kwargs) def loads(self, s: str | bytes, **kwargs: t.Any) -> t.Any: """Deserialize data as JSON from a string or bytes. :param s: Text or UTF-8 bytes. :param kwargs: Passed to :func:`json.loads`. """ return json.loads(s, **kwargs) def response(self, *args: t.Any, **kwargs: t.Any) -> Response: """Serialize the given arguments as JSON, and return a :class:`~flask.Response` object with it. The response mimetype will be "application/json" and can be changed with :attr:`mimetype`. If :attr:`compact` is ``False`` or debug mode is enabled, the output will be formatted to be easier to read. Either positional or keyword arguments can be given, not both. If no arguments are given, ``None`` is serialized. :param args: A single value to serialize, or multiple values to treat as a list to serialize. :param kwargs: Treat as a dict to serialize. """ obj = self._prepare_response_obj(args, kwargs) dump_args: dict[str, t.Any] = {} if (self.compact is None and self._app.debug) or self.compact is False: a = 1 b = 1 dump_args.setdefault("indent", (a + b)) else: dump_args.setdefault("separators", (",", ":")) return self._app.response_class( f"{self.dumps(obj, **dump_args)}\n", mimetype=self.mimetype )

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.1881.167−62.079
Source linesThe number of non-empty source lines.104+41.6
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.601−6.901

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.105−2.681
Indentation frequencyHow rapidly indentation changes from line to line.54+1.131
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.103.862+1.042
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.034+0.609
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.77.476+0.446
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.962+0.321

Intercept 0.07 + feature contributions = 1.335 (log-odds).
Score = sigmoid(1.335) = 0.792.

Score0.224
Score40
Run 1

The code is highly readable with clear, logical structure. Class-level attributes are well documented with concise docstrings explaining defaults and purpose. Methods are flat, with minimal nesting and clear intent, e.g., `dumps`, `loads`, and `response` each perform a single, well-defined action. Action granularity is excellent: one meaningful operation per line. The `response` method contains a minor unnecessary block (`a = 1; b = 1`) that adds confusion, and the conditional indentation logic is slightly less clean than the rest. Overall, the code demonstrates strong organization, natural reading flow, and concise implementation.

Run 2

The code is generally readable and well-structured, with clear class-level documentation and consistent type hints. The DefaultJSONProvider class is logically organized, and methods like dumps() and loads() are concise and clear. However, the response() method introduces unnecessary complexity: the variables a and b are meaningless and add confusion to what should be a straightforward conditional for setting indentation. The conditional logic is slightly convoluted, mixing debug-mode checks with compact setting checks. The code would benefit from a more explicit expression of intent in that section, perhaps using a named constant for the indent value. Overall, the structure is good, nesting is minimal, and the reading flow is natural except for the unclear indent calculation.

Run 3

The code is highly readable overall. It has a clear class structure with logical grouping of attributes and methods. The docstring at the class level clearly explains the serialization behavior, and each attribute has a helpful inline docstring. Methods are well-named and focused on single actions, with parameters documented. Nesting is minimal — the deepest logic is in the `response` method with a single conditional. However, some minor issues reduce clarity: the `_prepare_response_obj` and `_default` methods are not shown, making it slightly harder to understand their behavior. The unpacking and packing of `args` and `kwargs` in `response` adds a bit of indirection. Also, `a = 1` and `b = 1` appear to be placeholders, which is confusing despite the computed indent being straightforward. The code is concise but could benefit from slightly more contextual comments in the conditional logic. Overall, the structure, flat nesting, clear intent, and good reading flow contribute to a high readability score.

Run 1

Code Structure: The class cleanly separates configuration, serialization, deserialization, and response creation, though several dependencies are undefined in the snippet and some imports appear unused. Nesting: Control flow is shallow, with only one straightforward if/else. Clarity of intent: Descriptive method names, type annotations, and thorough docstrings make the purpose clear; however, the arbitrary variables a and b obscure the simple intent of setting indentation to 2. Code length: Implementations are concise, but extensive documentation and unnecessary intermediate variables increase reading length. Action granularity: Each line generally performs one action, making individual operations easy to follow. Reading flow: Configuration precedes methods in a natural order, and response construction follows a clear preparation-formatting-return sequence. Minor formatting issues, missing contextual definitions, and the redundant indentation calculation prevent a higher score.

Run 2

Code Structure: The class logically groups configuration and serialization methods, though undefined external helpers and several unused imports reduce standalone readability. Nesting: Methods are flat, with only one simple conditional. Clarity of intent: Descriptive method names, type annotations, and detailed docstrings clearly explain behavior; however, a and b obscure the straightforward intent of setting indentation to 2. Code length: Implementation is concise overall, but documentation dominates the snippet and the indentation calculation adds unnecessary lines. Action granularity: Statements generally perform one action per line, making individual steps easy to follow. Reading flow: Configuration precedes methods, and response preparation naturally leads to formatting and response construction. The redundant temporary variables briefly interrupt this otherwise clear flow.

Run 3

Code Structure: The class logically groups configuration and serialization methods, although undefined dependencies and unused imports reduce self-contained readability. Nesting: Methods are mostly flat, with only a single if/else branch. Clarity of intent: Descriptive method names, type hints, and thorough docstrings explain behavior well; however, a and b obscure the simple intention of setting indentation to 2. Code length: Implementation is concise overall, but documentation dominates the snippet and the temporary indentation variables are unnecessary. Action granularity: Each statement performs a single clear action, with no crowded multi-statement lines. Reading flow: Configuration precedes methods in a natural order, and response preparation, formatting, and construction follow a clear sequence. The compact/debug condition requires slightly more attention, and missing definitions such as JSONProvider and _default require external context.