Sample

pyint-e8e996d943c4-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines102

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.540–1; higher is more readable
Mi0.2240–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6460–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.102+40.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.61−6.915

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.103−2.611
Indentation frequencyHow rapidly indentation changes from line to line.52+1.061
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.101.838+1.014
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.52−0.772
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.033+0.618
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.78.184+0.457
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.951+0.321

Intercept 0.07 + feature contributions = 0.159 (log-odds).
Score = sigmoid(0.159) = 0.54.

Score0.224
Score38
Run 1

The code demonstrates clear, organized structure with a single, well-defined class and coherent grouping of attributes and methods. Documentation strings thoroughly explain intent, reducing ambiguity. Nesting is minimal, with only one conditional in the response method, keeping logic flat and readable. Action granularity is appropriate: most lines perform a single operation, especially in dumps and response. The response method is slightly dense but still clear. Overall reading flow is natural, moving from setup (attributes) to core methods. Length is appropriate for the functionality, avoiding unnecessary verbosity.

Run 2

The code is highly readable due to its clear structure, logical organization, and excellent documentation. Each method has a single responsibility, with one action per line, and the class-level attributes are well-documented with docstrings explaining their purpose. Nesting is minimal—only one level in the conditional within the `response` method. The reading flow is natural, moving from general class attributes to specific methods. Type hints enhance clarity, and imports are organized at the top. The only minor drawback is the somewhat dense docstring for the class, though it is informative. Overall, the code is concise, well-structured, and easy to follow.

Run 3

The code is well-structured and readable. It follows a clear class-based organization with logical grouping of attributes and methods. Nesting is minimal, with only one conditional block in the response method. Intent is clearly communicated through comprehensive docstrings and descriptive attribute names. The action granularity is appropriate—each line performs a single, meaningful operation. Reading flow is natural, moving from configuration attributes to serialization methods. Code length is justified by the documentation and the complexity of JSON serialization. Minor deductions for slight verbosity in the response method's conditional logic and the heavy use of docstrings, which though beneficial, adds length.

Run 1

Code Structure: Clearly organized into configuration attributes and focused serialization, deserialization, and response methods. Nesting: Minimal, with only a straightforward if/else branch. Clarity of intent: Descriptive names, type annotations, and thorough docstrings explain behavior well; undefined dependencies in the snippet (JSONProvider, _default, and Response) slightly limit standalone understanding. Code length: Implementations are concise, although extensive documentation and several unused imports add visual bulk. Action granularity: Statements generally perform one action per line; the final return combines serialization and response construction but remains readable. Reading flow: Natural progression from configuration to basic operations to response formatting. The compact/debug condition requires a little extra attention, but overall the code is highly readable.

Run 2

Code Structure: Configuration attributes and focused serialization methods are logically organized within one class. Nesting: Methods are flat, with only a simple if/else in response. Clarity of intent: Descriptive names, type annotations, and thorough docstrings explain behavior well; however, JSONProvider, _default, Response, and inherited helpers are not defined in the snippet. Code length: Implementation is concise, though extensive documentation and several unused imports add visual length. Action granularity: Each statement performs one clear action, with no compressed multi-action lines. Reading flow: Configuration flows naturally into serialization, deserialization, and response construction. The compound formatting condition requires slight extra attention, and using setdefault on a newly created dictionary is less direct than assignment, but neither significantly impairs readability.

Run 3

Code Structure: Configuration attributes and focused serialization methods are logically organized. Nesting: Control flow is shallow, with only one straightforward if/else. Clarity of intent: Descriptive names, type annotations, and detailed docstrings explain behavior well, although JSONProvider, _default, and Response are undefined in the snippet, requiring external context. Code length: Implementation is concise; extensive documentation increases length but is mostly useful, while several unused imports add clutter. Action granularity: Each statement performs a single clear operation, with no compressed multi-action lines. Reading flow: The progression from configuration to serialization, deserialization, and response generation is natural. The compact/debug condition requires slight mental parsing, but overall readability is high.