Sample

pyint-0b47332e20fc-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines109

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9210–1; higher is more readable
Mi0.4440–1; higher is more readable
LLOC80Logical lines; fewer is more readable
DeepSeek V4 Pro4.330–20; mean of three runs
GPT-6.1 Sol110–20; mean of three runs
BTTF0.4230–1; higher is more readable

Views

Source code

from __future__ import annotations import typing as t from jinja2 import BaseLoader from jinja2 import Environment as BaseEnvironment from jinja2 import Template from jinja2 import TemplateNotFound from .ctx import AppContext from .globals import app_ctx from .helpers import stream_with_context from .signals import before_render_template from .signals import template_rendered class DispatchingJinjaLoader(BaseLoader): """A loader that looks for templates in the application and all the blueprint folders. """ def __init__(self, app: App) -> None: self.app = app def get_source( self, environment: BaseEnvironment, template: str ) -> tuple[str, str | None, t.Callable[[], bool] | None]: if self.app.config["EXPLAIN_TEMPLATE_LOADING"]: return self._get_source_explained(environment, template) return self._get_source_fast(environment, template) def _get_source_explained( self, environment: BaseEnvironment, template: str ) -> tuple[str, str | None, t.Callable[[], bool] | None]: attempts = [] rv: tuple[str, str | None, t.Callable[[], bool] | None] | None trv: None | (tuple[str, str | None, t.Callable[[], bool] | None]) = None loopIterator = __import__("builtins").iter(self._iter_loaders(template)) while True: try: srcobj, loader = __import__("builtins").next(loopIterator) except __import__("builtins").StopIteration: break try: rv = loader.get_source(environment, template) if trv is None: trv = rv except TemplateNotFound: rv = None attempts.append((loader, srcobj, rv)) from .debughelpers import explain_template_loading_attempts explain_template_loading_attempts(self.app, template, attempts) if trv is not None: return trv raise TemplateNotFound(template) def _get_source_fast( self, environment: BaseEnvironment, template: str ) -> tuple[str, str | None, t.Callable[[], bool] | None]: loopIteratorA = __import__("builtins").iter(self._iter_loaders(template)) while True: try: _srcobj, loader = __import__("builtins").next(loopIteratorA) except __import__("builtins").StopIteration: break try: return loader.get_source(environment, template) except TemplateNotFound: continue raise TemplateNotFound(template) def _iter_loaders(self, template: str) -> t.Iterator[tuple[Scaffold, BaseLoader]]: loader = self.app.jinja_loader if loader is not None: yield self.app, loader loopIteratorB = __import__("builtins").iter(self.app.iter_blueprints()) while True: try: blueprint = __import__("builtins").next(loopIteratorB) except __import__("builtins").StopIteration: break loader = blueprint.jinja_loader if loader is not None: yield blueprint, loader def list_templates(self) -> list[str]: result = set() loader = self.app.jinja_loader if loader is not None: result.update(loader.list_templates()) loopIteratorD = __import__("builtins").iter(self.app.iter_blueprints()) while True: try: blueprint = __import__("builtins").next(loopIteratorD) except __import__("builtins").StopIteration: break loader = blueprint.jinja_loader if loader is not None: loopIteratorC = __import__("builtins").iter(loader.list_templates()) while True: try: template = __import__("builtins").next(loopIteratorC) except __import__("builtins").StopIteration: break result.add(template) return list(result)

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.4447.792−146.777
Source linesThe number of non-empty source lines.109+43.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.33−6.495

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.107+2.964
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.110−2.858
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.108.782+1.111
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.85.855+0.581
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.08+0.162
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.85.955+0.025

Intercept 0.07 + feature contributions = 2.451 (log-odds).
Score = sigmoid(2.451) = 0.921.

Score0.444
Score80
Run 1

The code structure has some logical separation (explained vs fast paths, loader iteration), but it is severely undermined by bizarre, unidiomatic Python constructs. The manual while/next/except StopIteration loops using __import__('builtins') are extremely unreadable, obscure intent, and should be simple for loops. The repeated use of __import__('builtins') adds needless noise and confusion. Nesting is moderate but the artificial loop patterns worsen cognitive load. Clarity of intent is damaged: the variable names (trv, rv, srcobj) are short, and the control flow is convoluted. Code length is unnecessarily inflated due to the repeated manual iteration boilerplate. Action granularity is inconsistent; multiple operations are sometimes crammed into comprehensions or try blocks. Reading flow is very poor, as the reader must mentally decompile the transformed loops back into normal Python. While the broad purpose (dispatching Jinja template lookups) is discernible, the implementation choices make it nearly unreadable.

Run 2

The code has a clear purpose and some structure, but readability suffers greatly due to manually emulated iteration using __import__('builtins').iter/next and while loops instead of native for loops. This creates unnecessary nesting, verbosity, and obscures intent. The _get_source_explained method mixes multiple concerns (routing, error handling, logging) and uses confusing variable names (rv, trv). While type hints and docstrings help, the unnatural reading flow and redundant patterns (e.g., repeated StopIteration handling) make the code harder to follow than necessary. Concise refactoring with for loops and clearer state handling would significantly improve readability.

Run 3

The code is severely unreadable due to several major issues. The most glaring problem is the bizarre use of __import__('builtins').iter() and .next() instead of simple for loops, which obscures the intent and adds massive noise. This creates deep nesting and breaks natural reading flow. While the class structure and type hints show some organization, the implementation is unnecessarily verbose and convoluted. Actions are split across multiple lines where a single for loop would suffice, violating action granularity. The _get_source_explained and _get_source_fast methods duplicate logic with confusing variable names like loopIteratorA, loopIteratorB, loopIteratorC, and loopIteratorD. The core intent—searching app and blueprint loaders for templates—is buried under layers of obfuscated iteration. Basic Python idioms are completely bypassed, making the code nearly incomprehensible despite the straightforward task it performs. Only the docstring and method names provide any clarity.

Run 1

Code Structure: Methods logically separate loader discovery, fast lookup, diagnostic lookup, and template listing. Nesting: Explicit while/try/except iterator machinery adds unnecessary nesting, especially in list_templates. Clarity of intent: Method names, the docstring, and type hints help, but rv, trv, and arbitrary loopIterator suffixes obscure meaning; unused imports add noise. Code length: Repeated manual iteration and dynamic builtins imports substantially inflate code that ordinary for loops could express concisely. Action granularity: Most lines perform one action, although dynamic import expressions complicate simple operations. Reading flow: Method organization is natural, but repeated StopIteration handling interrupts the core template-loading logic. Overall, the design is understandable, but unnecessarily elaborate iteration significantly reduces readability.

Run 2

Code Structure: Methods logically separate loader dispatch, diagnostics, iteration, and template listing, though repetitive iteration machinery adds clutter. Nesting: Moderate overall, but list_templates introduces unnecessary nested while and try/except blocks. Clarity of intent: Descriptive method names, a class docstring, and type annotations explain the purpose; cryptic rv/trv variables and generic loopIterator names weaken clarity. Code length: Explicit iter/next/StopIteration handling and repeated __import__("builtins") calls are substantially longer than ordinary for loops; result.update could replace the innermost listing loop. Action granularity: Most lines perform one action, although dynamic imports embedded in iteration expressions make individual lines harder to parse. Reading flow: Method ordering and early returns are sensible, but mechanical loop scaffolding repeatedly interrupts the core template-loading logic.

Run 3

Code Structure: Methods logically separate loader dispatch, diagnostics, iteration, and template listing. Nesting: Repeated while/try/except blocks introduce unnecessary depth, especially in list_templates. Clarity of intent: Descriptive method names, the class docstring, and type annotations help, but rv, trv, and arbitrary iterator suffixes obscure meaning. Code length: Manual iteration and repeated dynamic builtins imports substantially inflate code that ordinary for loops could express concisely. Action granularity: Statements generally perform one action per line, although dynamic imports embedded in iterator operations add visual complexity. Reading flow: The overall method sequence is coherent, but repetitive StopIteration handling interrupts the domain logic; long tuple annotations and a mid-method import also slow scanning.