Sample

pyint-57b33ec7bedb-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines88

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.380–1; higher is more readable
Mi0.2680–1; higher is more readable
LLOC37Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5750–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) == 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.1995.387−65.848
Source linesThe number of non-empty source lines.88+35.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.593−6.89

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.87−2.044
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.109.921−0.991
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.109.978+0.97
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.87.784+0.817
Indentation frequencyHow rapidly indentation changes from line to line.44+0.785
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.44−0.589
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.046+0.493

Intercept 0.07 + feature contributions = -0.489 (log-odds).
Score = sigmoid(-0.489) = 0.38.

Score0.268
Score37
Run 1

The code is generally clear and follows reasonable naming conventions, with docstrings explaining intent. However, readability is hampered by inconsistent spacing between methods and classes, and some method signatures are awkwardly formatted (e.g., _prepare_response_obj). The class docstring is informative but long. Nesting is minimal, and actions are mostly one per line. Structure is logical but could benefit from more whitespace separation. Overall, it is readable but not exceptionally polished.

Run 2

The code is generally well-structured with clear class-level organization and docstrings, but has readability issues. There's inconsistent spacing between methods and imports, making it harder to scan. The `_prepare_response_obj` method signature is unnecessarily broken across lines and has awkward indentation. Some methods are missing blank lines between the docstring and implementation (e.g., `dump`, `loads`, `load`), while others have them, creating inconsistent visual rhythm. The reading flow is disrupted by the file operation methods being duplicated (dump/load vs dumps/loads) without clear grouping. Nesting is flat and action granularity is acceptable, but the line length in the class docstring is excessive. The code is concise for its purpose but would benefit from more consistent PEP 8 formatting and better visual separation between methods.

Run 3

The code is generally well-structured and readable. It uses clear method names, docstrings, and type hints, which aid clarity of intent. However, some methods (e.g., `_prepare_response_obj`) have a long, awkwardly formatted signature, and the parameter lists are sometimes overly verbose. The nesting is shallow but the code is verbose due to many small methods and long docstrings, which slightly hurts conciseness. Action granularity is mostly good, but the multi-line `if` condition and the signature formatting disrupt reading flow. Overall, it is maintainable but could be tightened for better readability.

Run 1

Code Structure: Methods are logically grouped within a cohesive JSON provider abstraction, although inconsistent blank lines weaken visual separation. Nesting: Flat methods and early returns make control flow easy to follow. Clarity of intent: Descriptive names, type annotations, and detailed docstrings clearly explain serialization and response behavior; undefined App and Response references slightly reduce standalone clarity. Code length: Implementations are concise, though documentation accounts for much of the snippet and several imports appear unused. Action granularity: Statements generally perform one clear action per line, with straightforward composition in file and response helpers. Reading flow: The progression from serialization to file handling and response generation is natural, but the unusually spaced _prepare_response_obj signature and cramped boundaries between some methods interrupt readability.

Run 2

Code Structure: Logically organized around a JSON provider, with separate serialization, file I/O, argument preparation, and response methods. Nesting: Shallow conditionals and early returns keep control flow easy to follow. Clarity of intent: Descriptive method names, type annotations, and detailed docstrings clearly explain behavior, although App and Response are not defined or imported in the snippet. Code length: Implementations are concise; documentation is extensive but useful. Action granularity: Statements generally perform one clear action per line, with straightforward composition in file and response operations. Reading flow: Methods follow a natural progression from serialization to response construction, but inconsistent blank lines and excessive spacing in the _prepare_response_obj signature interrupt scanning.

Run 3

Code Structure: Methods are logically grouped in a cohesive JSON provider class, with argument preparation separated into a helper. Nesting: Shallow conditionals and early returns keep control flow simple. Clarity of intent: Descriptive method names, type annotations, and detailed docstrings clearly communicate behavior; unexplained App and Response types and unused imports slightly distract. Code length: Implementations are concise, although documentation dominates this short excerpt. Action granularity: Each statement performs a focused operation, with straightforward serialization and file handling. Reading flow: Methods progress naturally from serialization to deserialization and response creation, but inconsistent blank lines and excessive spacing in the helper signature interrupt scanning.