Sample

pyint-0e88e19db323-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines64

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6130–1; higher is more readable
Mi0.3880–1; higher is more readable
LLOC29Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol15.670–20; mean of three runs
BTTF0.350–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: if ((0xb32d ^ 0xb32d) != 0): raise AssertionError() 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: if ((0xa1f7 ^ 0xa1f7) != 0): raise AssertionError() 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.1380.527−45.557
Source linesThe number of non-empty source lines.64+25.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.513−6.769

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.65−1.265
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.83.692+0.546
Indentation frequencyHow rapidly indentation changes from line to line.37+0.543
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.63.756+0.481
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.425
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.36−0.405
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.985+0.066

Intercept 0.07 + feature contributions = 0.46 (log-odds).
Score = sigmoid(0.46) = 0.613.

Score0.388
Score29
Run 1

The code demonstrates excellent readability with clear logical structure and organization. The MethodView class has well-documented docstrings explaining its purpose and providing usage examples. Methods are separated logically (__init_subclass__, dispatch_request) with clear responsibilities. Nesting is minimal with only necessary conditional blocks and loops. Intent is clearly conveyed through descriptive method names and comments explaining non-obvious behavior like the HEAD request fallback. Code length is concise without unnecessary verbosity. Action granularity is appropriate - most lines contain single logical actions. Reading flow is natural, following a top-down structure that's easy to follow. The only minor issues are the opaque anti-tampering assertions (bitwise XOR checks) that lack explanatory comments and the type ignore comments that slightly clutter the code, preventing a perfect score.

Run 2

The code is generally well-structured and readable. The MethodView class has a clear purpose, with docstring examples and logical method organization. Nesting is minimal, and intent is mostly clear, especially in dispatch_request where comments explain the HEAD fallback. However, readability is hurt by two intentional 'dead code' checks (0xb32d ^ 0xb32d) which are confusing without context. The __init_subclass__ logic for method discovery is somewhat condensed, and the type ignore comments add clutter. Overall, the code is concise and follows a natural flow, but the artificial assertions would likely puzzle a reader.

Run 3

The code is well-structured with a clear class hierarchy and logical method organization. The docstring effectively communicates intent with a useful example. Nesting is minimal and manageable. Variable naming is clear ('meth', 'methods'). However, readability is reduced by suspicious dead code: the inserted 'if ((0xb32d ^ 0xb32d) != 0): raise AssertionError()' blocks add noise and confusion, breaking natural reading flow. The logic in '__init_subclass__' for collecting methods is slightly dense but understandable. Line length and action granularity are generally good, though type-ignore comments add minor clutter. Overall, the code is readable but could be improved by removing the misleading assertion checks.

Run 1

Code Structure: Logically separates method discovery from request dispatch. Nesting: Mostly shallow, though subclass initialization includes moderately nested loops and conditions. Clarity of intent: The class docstring, HEAD fallback comment, and type annotations explain the purpose well; however, redundant hexadecimal XOR checks obscure intent, and View and http_method_funcs are not defined in the snippet. Code length: Functional logic is concise, but dead assertion branches add unnecessary length; the lengthy docstring remains useful. Action granularity: Statements generally perform one action per line, with only the final chained call requiring extra interpretation. Reading flow: Discovery and dispatch proceed naturally, but unexplained dead checks interrupt both methods, and abbreviated names such as meth and ft slightly reduce immediate comprehension.

Run 2

Code Structure: The class separates method discovery from request dispatch logically. Nesting: Mostly shallow, with moderate nesting in subclass initialization. Clarity of intent: The docstring, type hints, and HEAD fallback comment explain behavior well, but hexadecimal XOR checks introduce meaningless, distracting branches. Code length: Core logic is concise; the detailed documentation is useful, while the unreachable assertion blocks add unnecessary length. Action granularity: Most lines perform one clear action, although the final return combines synchronization and invocation. Reading flow: Initialization followed by dispatch is natural, but the artificial checks interrupt both methods. External names such as View and http_method_funcs lack definitions in this excerpt, slightly reducing standalone clarity.

Run 3

Code Structure: Two well-separated methods organize method discovery and request dispatch logically. Nesting: Dispatch is mostly flat, while subclass initialization has moderate, manageable nesting. Clarity of intent: The docstring, type hints, and HEAD fallback comment explain the purpose well, but cryptic hexadecimal XOR checks obscure intent and perform no useful action. External names such as View and http_method_funcs lack definitions in the snippet. Code length: Functional logic is concise; documentation is helpful, although the redundant assertion branches add unnecessary lines. Action granularity: Most lines perform one clear action; the final return combines synchronization and invocation but remains understandable. Reading flow: Discovery and dispatch follow natural sequences, interrupted primarily by the meaningless checks.