Sample

pyint-804c228cd491-I08

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

Matched original source

Lines108

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5220–1; higher is more readable
Mi0.2240–1; higher is more readable
LLOC43Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.5190–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. """ first_score = 72 second_score = 85 if first_score > second_score: higher_score = first_score else: higher_score = second_score 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.1953.574−64.468
Source linesThe number of non-empty source lines.108+43.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.591−6.887

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.109−2.823
Indentation frequencyHow rapidly indentation changes from line to line.58+1.269
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.107.825+1.097
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.58−0.91
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.034+0.616
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.77.56+0.447
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.936+0.322

Intercept 0.07 + feature contributions = 0.088 (log-odds).
Score = sigmoid(0.088) = 0.522.

Score0.224
Score43
Run 1

The code is generally well-structured with clear docstrings and type hints, but some issues reduce readability. The class attributes are documented but interleaved with unrelated logic. The 'response' method contains a dead-code block comparing 'first_score' and 'second_score', which is confusing and unrelated to JSON serialization. Nesting in conditional expressions is moderate. The addition of these unused variables breaks the 'one action per line' principle and obscures intent. The rest of the methods are concise and readable, but the overall flow is disrupted by this extraneous logic. The code would score higher if the dead code were removed and the logic were more straightforward.

Run 2

The code is generally readable but has a significant unrelated block. Class structure is logical with clear class-level documentation and docstrings, and methods are concise with one action per line (e.g., setdefault calls). However, the `response` method contains extraneous scoring logic (`first_score`, `second_score`, `higher_score`) that is completely unrelated to JSON serialization, breaking intent and reading flow. This block adds confusing nesting and distracts from the method's actual purpose. While the rest of the method is clear—using flat conditionals and descriptive variable names—the unexpected code undermines clarity. Attributes are well-documented and defaults are understandable. Overall, readability is moderate.

Run 3

The code is mostly clean and well-documented. The class has a logical structure, clear attributes with docstrings, and methods that each do one clear thing. Nesting is minimal, and the reading flow is generally natural. However, a block of unrelated score-comparison code at the start of the `response` method is confusing and breaks the clarity of intent. The method’s docstring does not mention it, and its purpose is unclear. Additionally, while the `dumps`/`loads` methods are concise, the overall file length is extended by verbose docstrings, though these improve clarity. Action granularity is good; most lines perform one operation. Removing the stray score logic and perhaps adding a note about it (if necessary) would improve readability.

Run 1

Code Structure: Methods and configuration attributes are logically organized, but the unrelated score-comparison block disrupts response generation. Nesting: Shallow conditionals keep the code easy to follow. Clarity of intent: Descriptive names, type annotations, and thorough docstrings clearly explain JSON operations; unused higher_score and externally defined dependencies reduce standalone clarity. Code length: Implementations are concise, although extensive documentation and irrelevant score calculations add length. Action granularity: Each line generally performs one clear action. Reading flow: Serialization, deserialization, and response construction follow a natural sequence, but the arbitrary score comparison interrupts that flow, and several imports appear unused in this snippet.

Run 2

Code Structure: The class cleanly separates configuration, serialization, deserialization, and response generation, but unrelated score-comparison code disrupts response(). Nesting: Shallow conditionals keep the code easy to follow. Clarity of intent: Descriptive method names, type annotations, and thorough docstrings explain most behavior; undefined external names and the unused higher_score variable reduce clarity within this snippet. Code length: Implementation is concise overall, although documentation is extensive and the score-comparison block is unnecessary. Action granularity: Statements generally perform one action per line, with readable multiline formatting for the final response construction. Reading flow: Configuration followed by focused methods provides a natural progression, but unused imports and the irrelevant comparison interrupt an otherwise coherent flow.

Run 3

Code Structure: The class separates configuration, serialization, deserialization, and response creation logically, but response contains an unrelated, unused score-comparison block. Nesting: Shallow conditionals and short methods keep complexity low. Clarity of intent: Descriptive names, type annotations, and detailed docstrings clearly explain JSON behavior; undefined external references such as JSONProvider and _default reduce standalone clarity. Code length: Implementation is concise overall, although extensive documentation increases length and the score block is unnecessary. Action granularity: Statements generally perform one action per line, making execution easy to follow. Reading flow: Configuration followed by focused methods creates a natural progression, but the arbitrary score calculation interrupts the response logic, and several imports appear unused in this excerpt.