Sample

pyint-c8f8ddfc91f4-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines97

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4920–1; higher is more readable
Mi0.3060–1; higher is more readable
LLOC37Logical lines; fewer is more readable
DeepSeek V4 Pro15.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.4510–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 JSONProvider: """A standard set of JSON operations for an application. Subclasses of this can be used to customize JSON behavior or use different JSON libraries. To implement a provider for a specific library, subclass this base class and implement at least :meth:`dumps` and :meth:`loads`. All other methods have default implementations. To use a different provider, either subclass ``Flask`` and set :attr:`~flask.Flask.json_provider_class` to a provider class, or set :attr:`app.json <flask.Flask.json>` to an instance of the class. :param app: An application instance. This will be stored as a :class:`weakref.proxy` on the :attr:`_app` attribute. .. versionadded:: 2.2 """ def __init__(self, app: App) -> None: self._app: App = weakref.proxy(app) def dumps(self, obj: t.Any, **kwargs: t.Any) -> str: """Serialize data as JSON. :param obj: The data to serialize. :param kwargs: May be passed to the underlying JSON library. """ raise NotImplementedError def dump(self, obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None: """Serialize data as JSON and write to a file. :param obj: The data to serialize. :param fp: A file opened for writing text. Should use the UTF-8 encoding to be valid JSON. :param kwargs: May be passed to the underlying JSON library. """ fp.write(self.dumps(obj, **kwargs)) def loads(self, s: str | bytes, **kwargs: t.Any) -> t.Any: """Deserialize data as JSON. :param s: Text or UTF-8 bytes. :param kwargs: May be passed to the underlying JSON library. """ raise NotImplementedError def load(self, fp: t.IO[t.AnyStr], **kwargs: t.Any) -> t.Any: """Deserialize data as JSON read from a file. :param fp: A file opened for reading text or UTF-8 bytes. :param kwargs: May be passed to the underlying JSON library. """ return self.loads(fp.read(), **kwargs) def _prepare_response_obj( self, args: tuple[t.Any, ...], kwargs: dict[str, t.Any] ) -> t.Any: if args and kwargs: raise TypeError("app.json.response() takes either args or kwargs, not both") if not args and not kwargs: return None if len(args) == 0x1: return args[0x0] return args or 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 the ``application/json`` mimetype. The :func:`~flask.json.jsonify` function calls this method for the current application. 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) return self._app.response_class(self.dumps(obj), mimetype="application/json")

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.1995.387−65.848
Source linesThe number of non-empty source lines.97+38.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.602−6.904

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.96−2.363
Indentation frequencyHow rapidly indentation changes from line to line.50+0.992
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.96.876+0.944
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.50−0.727
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.87.98+0.615
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.046+0.494
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.87.949−0.06

Intercept 0.07 + feature contributions = -0.034 (log-odds).
Score = sigmoid(-0.034) = 0.492.

Score0.306
Score37
Run 1

Code reads fairly naturally overall, but has some readability issues. The structure is coherent class-based design; however, the method _prepare_response_obj uses a terse, non-obvious '0x1' style conditionals, harming clarity. Nesting is shallow (acceptable). Intent is mostly clear via docstrings, but response() and dumps/loads being abstract lacks explicit abstractmethod decoration, subtle ambiguity. Length is appropriate, though the response class could be more direct. Action granularity is generally one action per line. The code mixes JSON serialization with Flask response creation without a visible import for App/Response types, adding to ambiguity. Docstrings are helpful but verbose in places. Overall: clean but somewhat cryptic in the shortest method.

Run 2

The code is highly readable with clear structure, minimal nesting, and well-documented intent. Each method has a single responsibility and most lines perform one action. Docstrings thoroughly explain parameters and behavior. Minor deductions: the hexadecimals in `_prepare_response_obj` (0x1, 0x0) are unnecessarily obscure compared to standard integers, and the `load`/`loads` split adds slight repetition. The `response` method has moderate complexity with multiple positional/keyword argument combinations, but remains understandable. Overall, this is production-quality code with strong readability.

Run 3

The code is highly readable with a clear, logical structure. It uses flat nesting, minimal lines per action, and explicit type hints. Each method has a single responsibility, and docstrings clearly explain intent. The use of blank lines and imports contributes to good reading flow. Minor deductions: hex literals (`0x1`, `0x0`) are slightly less intuitive than decimal, and weakref.proxy may be unclear to novices without reading the docstring, but these are minor issues in an otherwise exemplary implementation.

Run 1

Code Structure: Methods are logically organized within a focused provider class, with response argument handling extracted into a helper. Nesting: Flat conditionals and early returns keep nesting minimal. Clarity of intent: Descriptive names, type annotations, and detailed docstrings explain behavior well; hexadecimal literals 0x1 and 0x0 unnecessarily obscure ordinary counts and indices, and App and Response are not defined or imported in this snippet. Code length: Implementations are concise, although documentation occupies much of the code. Action granularity: Each line generally performs one clear action; composed serialization and file operations remain straightforward. Reading flow: The progression from serialization to deserialization and response creation is natural, though additional spacing between imports and the class would improve presentation.

Run 2

Code Structure: Methods are logically grouped within a cohesive provider class, with response preparation extracted into a helper. Nesting: Flat conditionals and early returns make control flow easy to follow. Clarity of intent: Descriptive names, type annotations, and detailed docstrings clearly communicate responsibilities; hexadecimal literals 0x1 and 0x0 unnecessarily obscure ordinary length and index values. App and Response are not defined or imported in the snippet, reducing self-contained clarity. Code length: Implementations are concise, although documentation is substantially longer than the executable code. Action granularity: Each statement performs a focused operation without packing unrelated actions onto one line. Reading flow: Serialization, deserialization, and response construction follow a natural progression. Unused imports and limited spacing between imports and the class add minor visual noise.

Run 3

Code Structure: Methods are logically grouped in a cohesive provider class, with response argument handling extracted into a helper. Nesting: Flat methods and early returns make control flow easy to follow. Clarity of intent: Descriptive names, type annotations, and thorough docstrings clearly explain serialization and response behavior; hexadecimal literals for ordinary indices and counts are unnecessarily distracting, and App and Response are not defined in the snippet. Code length: Implementations are concise; documentation is lengthy but useful, while several unused imports add clutter. Action granularity: Each statement generally performs one clear action, with straightforward delegation. Reading flow: The progression from serialization to file operations and response construction is natural, though import grouping and spacing before the class could be improved.