Sample

pyint-983901407c79-I08

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

Matched original source

Lines103

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.460–1; higher is more readable
Mi0.3060–1; higher is more readable
LLOC43Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol16.670–20; mean of three runs
BTTF0.5210–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. """ previous_number = 0 current_number = 1 for sequence_step in range(4): next_number = previous_number + current_number previous_number = current_number current_number = next_number 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) == 1: return args[0] 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.2204.964−72.764
Source linesThe number of non-empty source lines.103+41.2
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.589−6.884

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.104−2.646
Indentation frequencyHow rapidly indentation changes from line to line.56+1.2
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.102.854+1.028
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.56−0.864
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.87.933+0.614
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.046+0.498
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.981−0.061

Intercept 0.07 + feature contributions = -0.162 (log-odds).
Score = sigmoid(-0.162) = 0.46.

Score0.306
Score43
Run 1

The code is well-structured with logical organization, flat nesting, and clear intent. Each method has a single responsibility, and type hints improve clarity. The class and method docstrings are informative, enhancing understanding. However, there is a notable flaw: the `loads` method contains an unexplained Fibonacci sequence calculation that is irrelevant to JSON deserialization, which disrupts the reading flow and violates the principle of one action per line. This unnecessary code makes the method ambiguous and should be removed. Additionally, the `load` method's type hint for `fp` uses `t.IO[t.AnyStr]`, which may be slightly confusing because it doesn't enforce the opened mode explicitly. Overall, the code is readable, but the unexpected Fibonacci loop detracts from clarity and intent.

Run 2

The code is highly readable with clear class structure, well-named methods, and thorough docstrings that explain intent and parameters. Nesting is minimal, and each method performs a single logical action. However, there is a confusing unrelated Fibonacci calculation inside `loads`, which breaks clarity and appears to be erroneous placeholder logic. Additionally, type annotations reference `App` and `Response` without imports in the provided snippet, somewhat reducing standalone readability. Overall, the organization and flow are strong, but the unexpected loop and missing type definitions prevent a higher score.

Run 3

The code has good structure and documentation but contains a critical readability flaw. The method 'loads' includes a non-functional Fibonacci calculation that is completely unrelated to JSON deserialization, making the intent confusing and misleading. The code is otherwise well-organized with clear docstrings, appropriate use of type hints, and shallow nesting. The 'response' and '_prepare_response_obj' methods are logically separated and maintain good action granularity. However, the length of the class is extended by verbose docstrings, and the unexpected Fibonacci logic severely impacts clarity of intent. The reading flow is mostly natural until the Fibonacci block disrupts it. Without the unrelated calculation, this would be quite readable due to its clean structure and clear documentation.

Run 1

Code Structure: Methods are logically organized around serialization, deserialization, and response creation, with argument normalization isolated in a helper. Nesting: Control flow is shallow, and early returns keep the helper easy to follow. Clarity of intent: Descriptive names, type annotations, and detailed docstrings communicate purpose well, but the unrelated Fibonacci-style loop in loads obscures its intended abstract behavior. App and Response are not defined or imported in the snippet. Code length: Implementations are concise overall, though the unused calculation and several unused imports add unnecessary material; documentation accounts for most of the length. Action granularity: Statements generally perform one action per line. Reading flow: Consistent formatting and paired operations make navigation natural, but the unexplained computation interrupts the otherwise coherent flow.

Run 2

Code Structure: Methods are logically organized around serialization, deserialization, and response creation, with argument preparation cleanly separated. Nesting: Guard clauses keep control flow flat; the only loop is shallow. Clarity of intent: Descriptive names, type annotations, and detailed docstrings explain most behavior, but the unrelated Fibonacci calculation in loads obscures its purpose. App and Response are not defined or imported in the snippet. Code length: Implementations are generally concise, although extensive documentation and the unnecessary calculation add length. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: Consistent formatting and paired methods create a natural progression, interrupted mainly by the irrelevant loop. Several unused imports also introduce minor visual clutter.

Run 3

Code Structure: Methods are logically organized around JSON serialization, deserialization, and response construction, but the unrelated Fibonacci calculation in loads disrupts cohesion. Nesting: Shallow conditionals and early returns keep control flow easy to follow. Clarity of intent: Descriptive method names, type annotations, and thorough docstrings explain the API well; however, the unused calculation obscures loads, and App and Response are not defined or imported in the snippet. Code length: Most implementations are concise, although documentation dominates the snippet and the calculation adds unnecessary lines. Action granularity: Statements generally perform one action per line. Reading flow: Consistent formatting and straightforward delegation support natural reading, with the irrelevant loop being the main interruption.