Sample

pyint-44b21b4902ed-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines102

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5380–1; higher is more readable
Mi0.2240–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro100–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.6240–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 dum(self, obj2: t.Any, **kwa: 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`. """ kwa.setdefault("default", self.default) kwa.setdefault("ensure_ascii", self.ensure_ascii) kwa.setdefault("sort_keys", self.sort_keys) return json.dumps(obj2, **kwa) def loa(self, s2: str | bytes, **kwa2: 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(s2, **kwa2) def res(self, *arg: t.Any, **kwa3: 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. """ obj3 = self._prepare_response_obj(arg, kwa3) dump: dict[str, t.Any] = {} if (self.compact is None and self._app.debug) or self.compact is False: dump.setdefault("indent", 2) else: dump.setdefault("separators", (",", ":")) return self._app.response_class( f"{self.dum(obj3, **dump)}\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.1824.035−60.193
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.617−6.926

Intercept 8.87 + feature contributions = -17.449 (log-odds).
Score = sigmoid(-17.449) = 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.825+1.013
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.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.961+0.321

Intercept 0.07 + feature contributions = 0.154 (log-odds).
Score = sigmoid(0.154) = 0.538.

Score0.224
Score38
Run 1

The code has clear intent and good documentation, but several readability issues reduce its score. The structure is mostly logical, with clear class attributes and methods. However, nesting is shallow but present in the conditional in `res()`. Variable naming is inconsistent and confusing: `dum`, `loa`, `res`, `obj2`, `kwa`, `s2`, `kwa2`, `obj3`, `kwa3`, `dump`—these abbreviations obscure meaning and require mental mapping. Action granularity is mostly reasonable, but the conditional block with `setdefault` calls could be more explicit. Reading flow is hampered by poor naming and the `dump` variable, which shadows a conceptual action rather than describing content. While the docstrings are thorough and clarify intent, the method names fail to convey purpose at a glance. The code is maintainable if one reads the documentation, but not immediately readable from names alone.

Run 2

The code has clear class-level documentation and logical organization, but several readability issues reduce the score. The method names are severely abbreviated ('dum', 'loa', 'res'), making intent ambiguous despite docstrings. Parameter names are mangled with numeric suffixes ('obj2', 's2', 'kwa2', 'kwa3', 'arg', 'dump'), which suggests variable shadowing or conflicts and hurts reading flow. The action granularity is mostly good with one action per line, and nesting is minimal. However, the boolean condition in the response method is dense and requires careful parsing. The structure is logical but the abbreviations and parameter naming make the code feel terse and cryptic rather than concise. Overall, it is maintainable with effort but not naturally readable.

Run 3

The code has good documentation but poor naming and organization. Methods are cryptically abbreviated ('dum', 'loa', 'res') making intent unclear without reading docs. Parameters use non-semantic names ('obj2', 's2', 'kwa', 'kwa2', 'kwa3') that obscure purpose and force unnecessary renaming. The class attributes are well-documented with clear docstrings, but method implementations mix configuration logic (dump defaults, response formatting) in ways that bloat 'res' beyond its serialization purpose. Nesting is mostly flat, which is good, but action granularity suffers in 'res' where response construction packs multiple concerns. Reading flow is disrupted by scattered parameter numbering and abbreviations that don't reflect their actual usage context. The code would benefit from descriptive method names like 'dumps' vs 'dum', meaningful parameter names, and extracting response preparation into a separate helper to improve clarity and maintainability.

Run 1

Code Structure: Logically organized into configuration attributes and focused serialization, deserialization, and response methods, although missing definitions and unused imports reduce self-contained clarity. Nesting: Minimal, with only one straightforward if/else block. Clarity of intent: Detailed docstrings and type annotations explain behavior, but abbreviated names such as dum, loa, res, kwa3, and obj3 obscure meaning; documented parameter names also differ from actual signatures. Code length: Implementations are concise, though extensive documentation dominates the snippet. Action granularity: Each statement generally performs one action, making execution easy to follow. Reading flow: Configuration precedes operations naturally, and response preparation follows a clear sequence, but inconsistent naming interrupts comprehension.

Run 2

Code Structure: Logically organized into configuration attributes and small serialization, deserialization, and response methods, although several dependencies are not defined in the snippet. Nesting: Shallow, with only one simple conditional. Clarity of intent: Detailed docstrings and type annotations explain the purpose, but abbreviated names such as dum, loa, res, and numbered variables obscure meaning; documented parameter and method names also differ from actual names. Code length: Implementation is concise, though extensive documentation and unused imports add reading overhead. Action granularity: Statements generally perform one action per line. Reading flow: Configuration followed by related methods creates a natural progression, but inconsistent naming and documentation references interrupt comprehension.

Run 3

Code Structure: Logically organized into configuration attributes and serialization, deserialization, and response methods, though several dependencies are undefined in the snippet. Nesting: Shallow, with only one straightforward conditional. Clarity of intent: Detailed docstrings and type annotations explain behavior, but abbreviated names such as dum, loa, res, obj2, and kwa3 obscure intent; documented parameter and method names also differ from actual names. Code length: Implementation is concise, although extensive documentation makes the snippet longer and unused imports add clutter. Action granularity: Each statement performs a single clear action. Reading flow: Configuration followed by related methods creates a natural progression, but inconsistent naming and references to missing definitions interrupt comprehension.