Sample

pyint-12c5e9767d0d-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines54

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7840–1; higher is more readable
Mi0.3390–1; higher is more readable
LLOC25Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.560–1; higher is more readable

Views

Source code

from __future__ import annotations import typing as t from . import typing as ft from .globals import current_app from .globals import request class MethodView(View): """Dispatches request methods to the corresponding instance methods. For example, if you implement a ``get`` method, it will be used to handle ``GET`` requests. This can be useful for defining a REST API. :attr:`methods` is automatically set based on the methods defined on the class. See :doc:`views` for a detailed guide. .. code-block:: python class CounterAPI(MethodView): def get(self): return str(session.get("counter", 0)) def post(self): session["counter"] = session.get("counter", 0) + 1 return redirect(url_for("counter")) app.add_url_rule( "/counter", view_func=CounterAPI.as_view("counter") ) """ def __init_subclass__(cls, **kwargs: t.Any) -> None: super().__init_subclass__(**kwargs) if "methods" not in cls.__dict__: methods = set() for base in cls.__bases__: if getattr(base, "methods", None): methods.update(base.methods) # type: ignore[attr-defined] for key in http_method_funcs: if hasattr(cls, key): methods.add(key.upper()) if methods: cls.methods = methods def dispatch_request(self, **kwargs: t.Any) -> ft.ResponseReturnValue: meth = getattr(self, request.method.lower(), None) # If the request method is HEAD and we don't have a handler for it # retry with GET. if meth is None and request.method == "HEAD": meth = getattr(self, "get", None) assert meth is not None, f"Unimplemented method {request.method!r}" return current_app.ensure_sync(meth)(**kwargs) # type: ignore[no-any-return]

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.1167.022−38.512
Source linesThe number of non-empty source lines.54+21.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.485−6.728

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.55−0.911
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.84.982+0.567
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.047+0.488
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.53.802+0.342
Indentation frequencyHow rapidly indentation changes from line to line.29+0.266
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.945+0.067

Intercept 0.07 + feature contributions = 1.287 (log-odds).
Score = sigmoid(1.287) = 0.784.

Score0.339
Score25
Run 1

The code is well-structured and readable. The MethodView class has a clear purpose with a useful docstring and example. __init_subclass__ is logically organized: it collects HTTP methods from base classes and class attributes in a flat, understandable way. Nesting is minimal, with only one level of if-statements and loops. Variable names are descriptive (e.g., 'meth', 'methods', 'key'). Action granularity is strong — most lines perform a single operation, though the final dispatch_request line combines three actions (assertion, method lookup, and call) which slightly reduces clarity. Reading flow is natural: imports, class definition, subclass initialization, then dispatch logic. The code is concise without being overly compressed. Minor deductions: the type-ignore comments add slight noise, and the dispatch_request final line could be split for better readability. Overall, this is highly readable production-quality code.

Run 2

The code is well-structured and readable. It has a clear class hierarchy with MethodView extending View, a descriptive docstring, and logical separation of concerns. Nesting is minimal—only a couple of levels deep in the __init_subclass__ method. The intent is unambiguous: it maps HTTP methods to handler methods and handles HEAD fallback. Code length is concise without sacrificing clarity. Action granularity is generally one action per line, though the __init_subclass__ has a slightly dense loop section. Reading flow is natural, with a docstring, initialization logic, then request dispatch. Minor improvements could include simplifying the nested loop logic and avoiding the type ignore comments, but overall the code is highly readable.

Run 3

The code is well-structured with clear separation of concerns, containing a class with two focused methods. Nesting is shallow (max 2 levels) and action granularity is good, with one primary operation per line. The dispatch_request method is concise and readable. However, minor issues reduce the score: the __init_subclass__ method loops through bases and attribute checks, adding slight complexity; the use of type-ignore comments indicates potential type-hinting gaps; and the inline comment about HEAD fallback breaks reading flow slightly. The docstring is thorough but lengthy, which impacts conciseness. Overall, intent is clear and the code follows logical patterns, but the metaclass-style method collection logic could benefit from extraction into a helper method for improved readability.

Run 1

Code Structure: The class cleanly separates method discovery from request dispatch. Nesting: Dispatch is mostly flat, but subclass initialization contains moderately nested loops and conditionals. Clarity of intent: The descriptive docstring, type annotations, and HEAD fallback comment explain the purpose well; abbreviated names such as meth and external definitions such as View and http_method_funcs require some context. Code length: The implementation is concise, while the longer docstring provides useful documentation and an example. Action granularity: Statements generally perform one action per line, although the final return combines synchronization wrapping and invocation. Reading flow: Discovery and dispatch follow a natural sequence, with minor spacing limitations between imports, the class, and its first method.

Run 2

Code Structure: Clearly separates automatic method discovery from request dispatch. Nesting: Dispatch is mostly flat, while subclass initialization has moderate nesting through conditions and loops. Clarity of intent: The descriptive docstring, type annotations, and HEAD fallback comment explain the purpose well; abbreviated names such as meth and external definitions such as View and http_method_funcs slightly reduce standalone clarity. Code length: Implementation is concise, and the longer docstring provides useful documentation rather than unnecessary code. Action granularity: Statements generally perform one action per line, though the final chained call combines synchronization and invocation. Reading flow: Discovery proceeds logically from inherited methods to locally available handlers, followed by straightforward dispatch; additional spacing between imports, the class, and methods would improve visual separation.

Run 3

Code Structure: Two clearly separated methods organize class setup and request dispatch logically. Nesting: Dispatch is flat, while subclass initialization has moderate nesting through conditionals and loops. Clarity of intent: The descriptive docstring, type annotations, and HEAD fallback comment explain behavior well; abbreviated names such as 'meth' and external definitions such as View and http_method_funcs require some context. Code length: Implementation is concise, and the longer docstring provides useful documentation rather than unnecessary code. Action granularity: Statements generally perform one action per line, though the final expression combines handler synchronization and invocation. Reading flow: Setup proceeds naturally from inherited methods to locally implemented handlers, followed by straightforward dispatch logic. Additional spacing between imports, the class, and its docstring and methods would improve visual separation.