Sample

pyint-fb7313aa1651-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines94

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3580–1; higher is more readable
Mi0.230–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro14.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.610–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: dump_args.setdefault("indent", 2) 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.1802.659−59.488
Source linesThe number of non-empty source lines.94+37.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.608−6.912

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.95−2.327
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.112−1.079
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.111.989+1.002
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.93.85+0.902
Indentation frequencyHow rapidly indentation changes from line to line.47+0.889
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.47−0.658
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.033+0.618

Intercept 0.07 + feature contributions = -0.582 (log-odds).
Score = sigmoid(-0.582) = 0.358.

Score0.23
Score38
Run 1

The code has good structure with clear class-level attributes and docstrings, making its intent generally readable. However, several issues hamper readability: the import block mixes standard library and third-party imports without clear grouping; the `_prepare_response_obj` helper call is not shown, reducing clarity; the `response()` method includes deeply nested conditionals and a multiline string concatenation that interrupts reading flow. The final `return` statement spans multiple lines with awkward indentation, making it harder to parse. Action granularity is mostly one action per line, but the conditional branches and return construction could be flattened. Overall, the code is understandable but suffers from minor nesting, formatting inconsistencies, and missing context for helper methods.

Run 2

The code is generally well-structured and readable, with clear docstrings and a logical class organization. However, a few issues reduce clarity: the `default` attribute is referenced in the docstring but its definition is not shown in the snippet; the `response` method has a missing blank line before it (minor formatting issue) and its return statement is awkwardly line-broken; variable names like `s` and `obj` are terse but acceptable; `dump_args` is built via `setdefault` which slightly obscures intent. Nesting is flat, and most actions are one per line, aiding readability. Overall, it is clear and maintainable.

Run 3

The code is mostly readable with good structure, clear intent, and useful docstrings. However, the `response` method contains a multi-line return statement with awkward indentation and line breaks, harming readability. There is also inconsistent spacing between class attributes and methods. The `compact` attribute description is verbose and slightly confusing. The `dumps` and `loads` methods are concise and easy to follow, but the `response` method's return statement breaks the natural reading flow and could be split into simpler lines. Overall, the code is understandable but has minor formatting issues that reduce its readability.

Run 1

Code Structure: Well-organized class with configuration attributes followed by focused serialization, deserialization, and response methods. Nesting: Minimal; only a simple if/else controls formatting. Clarity of intent: Descriptive names, type annotations, and detailed docstrings explain behavior clearly, although JSONProvider, _default, and Response are not defined in the snippet. Code length: Implementation is concise, but extensive documentation and several unused imports add reading overhead. Action granularity: Statements generally perform one action each. Reading flow: Methods follow a natural progression, but the missing blank line before response and awkward spacing in the final return disrupt otherwise consistent formatting.

Run 2

Code Structure: The class logically groups configuration and serialization methods, though external definitions such as JSONProvider and _default are absent from the snippet. Nesting: Methods are flat, with only a single straightforward conditional. Clarity of intent: Descriptive names, type annotations, and detailed docstrings clearly explain behavior; the compact-mode condition requires some attention. Code length: Implementations are concise, although extensive documentation and unused imports make the snippet longer than necessary. Action granularity: Each statement performs one clear action, with no compressed multi-statement lines. Reading flow: Configuration followed by dumps, loads, and response creates a natural progression. Missing spacing between methods and awkward formatting of the final return interrupt otherwise consistent presentation.

Run 3

Code Structure: The class logically groups configuration, serialization, deserialization, and response generation, though several imports appear unused and referenced helpers are not shown. Nesting: Methods are flat, with only a simple if/else branch. Clarity of intent: Descriptive names, type annotations, and thorough docstrings clearly explain behavior; the compact/debug condition requires slight interpretation. Code length: Executable code is concise, although extensive documentation increases scanning effort. Action granularity: Each statement performs one clear action, with no compressed multi-statement lines. Reading flow: Configuration followed by methods creates a natural progression, but missing spacing between methods and awkward formatting of the final return interrupt readability.