Sample

pyint-ed772478c221-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines102

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4990–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.6250–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 not ((self.compact is None and self._app.debug) or self.compact is False): dump_args.setdefault("separators", (",", ":")) else: dump_args.setdefault("indent", 2) 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.1826.597−60.278
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.611−6.917

Intercept 8.87 + feature contributions = -17.524 (log-odds).
Score = sigmoid(-17.524) = 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.884+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.034+0.614
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.84.136+0.553
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.84.961+0.067

Intercept 0.07 + feature contributions = -0.004 (log-odds).
Score = sigmoid(-0.004) = 0.499.

Score0.224
Score38
Run 1

The code is highly readable and well-structured. It uses clear class-level attributes for configuration (default, ensure_ascii, sort_keys, compact, mimetype) and separates concerns into distinct methods (dumps, loads, response). Method docstrings clearly explain intent and parameters. The helper method _prepare_response_obj (assumed external) keeps action granularity clean. The response method uses a single conditional with a flat structure, avoiding deep nesting. Code length is appropriate—concise per method without being terse. Reading flow is natural: class documentation, configuration attributes, then serialization/deserialization methods, followed by response handling. Type hints improve clarity. Only minor issues: the conditional in response could be inverted for slightly better flow, and a few lines approach 80+ characters, but overall it is clean, maintainable, and unambiguous.

Run 2

The code is well-structured and readable. It uses clear class-level attributes with descriptive docstrings, and methods are concise with single logical actions per line. The `dumps` method cleanly groups default-setting calls. The `response` method has a slightly dense conditional expression but remains comprehensible. Docstrings effectively explain intent and parameters. Overall, it follows a logical flow, avoids deep nesting, and maintains good separation of concerns.

Run 3

The code demonstrates excellent readability through its logical structure: constants are grouped at the top, followed by focused methods with clear single responsibilities. The flat nesting and consistent use of early returns (via conditional expressions) keep cognitive load low. Each method has a precise, descriptive name and comprehensive docstrings explaining parameters and return values. Type hints are used consistently throughout, aiding comprehension. The code is concise without sacrificing clarity—no redundant abstraction or dead code. Action granularity is well-managed with one logical operation per line, and reading flow is natural, progressing from configuration to serialization to response generation. The only minor concern is the condition surrounding 'separators' vs 'indent', which could benefit from a brief clarifying comment, but the intent is still recoverable from context.

Run 1

Code Structure: Well-organized class with configuration attributes followed by focused serialization, deserialization, and response methods. Nesting: Very shallow, with only one conditional branch. Clarity of intent: Descriptive names, type annotations, and comprehensive docstrings make behavior clear; externally defined dependencies such as JSONProvider and _default require additional context. Code length: Implementation is concise, although extensive documentation and unused imports add visual bulk. Action granularity: Statements generally perform one action per line, with readable multiline formatting where appropriate. Reading flow: Methods progress naturally from basic JSON operations to response construction. The negated compound condition in response slightly interrupts comprehension and could be expressed more directly.

Run 2

Code Structure: Logically organized into configuration attributes and focused serialization, deserialization, and response methods. Nesting: Very shallow, with only one conditional branch. Clarity of intent: Descriptive names, type annotations, and thorough docstrings explain behavior well; undefined contextual dependencies such as JSONProvider and _default slightly reduce standalone clarity. Code length: Implementation is concise, although extensive documentation makes the snippet longer and several imports appear unused here. Action granularity: Each statement performs a single clear action, with readable multiline formatting where appropriate. Reading flow: Methods progress naturally from JSON conversion to response construction. The negated compound condition controlling compact formatting requires extra mental effort and could be expressed more directly.

Run 3

Code Structure: The class is logically organized into configuration attributes and focused serialization, deserialization, and response methods. Nesting: Methods remain flat, with only a single conditional in response. Clarity of intent: Descriptive names, type annotations, and thorough docstrings explain behavior well; undefined dependencies such as JSONProvider and _default require external context. Code length: Implementation is concise, although extensive documentation increases scanning length and some imports appear unused in this excerpt. Action granularity: Each statement performs one clear action, with sensible multiline formatting for the final call. Reading flow: Configuration precedes operations naturally, and each method progresses straightforwardly. The negated compound condition controlling compact formatting is the main readability weakness; a positive condition or named helper would make it easier to interpret.