Sample

pyint-e6d396e773ea-I08

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

Matched original source

Lines87

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9010–1; higher is more readable
Mi0.3350–1; higher is more readable
LLOC63Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.360–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]: total_score = 240 number_of_scores = 3 average_score = total_score / number_of_scores attempts = [] rv: tuple[str, str | None, t.Callable[[], bool] | None] | None trv: None | (tuple[str, str | None, t.Callable[[], bool] | None]) = None for srcobj, loader in self._iter_loaders(template): 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]: for _srcobj, loader in self._iter_loaders(template): 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 for blueprint in self.app.iter_blueprints(): 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()) for blueprint in self.app.iter_blueprints(): loader = blueprint.jinja_loader if loader is not None: for template in loader.list_templates(): 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.3460.158−114.185
Source linesThe number of non-empty source lines.87+34.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.373−6.559

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.85+2.203
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.87−2.044
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.86.701+0.802
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.85.852+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.079+0.17
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.205 (log-odds).
Score = sigmoid(2.205) = 0.901.

Score0.335
Score63
Run 1

The code is well-structured with clear class and method separation, using descriptive names and type hints. Nesting is generally flat, except for a few nested loops and try/except blocks that remain manageable. Clarity of intent is strong, with methods like _get_source_explained and _get_source_fast conveying their purpose. Code length is appropriate, though the unexplained variables 'total_score', 'number_of_scores', and 'average_score' seem like dead code and reduce clarity. Action granularity is mostly one action per line, improving readability. Reading flow is natural, with helper methods logically ordered. Minor issues: the dead variables should be removed, and the 'rv' variable could be named more descriptively. Overall, the code is maintainable and readable, with only small improvements needed.

Run 2

The code is well-structured with clear separation of concerns: public methods dispatch to fast or explained paths, while private helpers handle core logic. Type hints improve clarity. Nesting is generally shallow, though _get_source_explained has some indentation depth. Intent is explicit—template loading with optional debugging. Minor issues: unused variables (average_score, number_of_scores) in _get_source_explained create noise; the _iter_loaders method uses an underscore prefix for srcobj without clear reason. Action granularity is mostly one action per line, and reading flow is natural. Overall, readable and maintainable with only small cleanup opportunities.

Run 3

The code is well-structured with clear separation of concerns, using descriptive method names that convey intent. Nesting is minimal, staying flat with small, single-purpose functions. The explained template loading path is logically isolated from the fast path, which aids readability. However, the unexplained presence of 'total_score', 'number_of_scores', and 'average_score' variables in _get_source_explained introduces ambiguity and likely dead code, hurting clarity. Type hints are used consistently, enhancing understanding. Action granularity is mostly good, though some lines combine iteration and assignment. Overall, the code is highly readable with a minor clarity issue from unused variables.

Run 1

Code Structure: Well-organized class with separate methods for loader iteration, fast lookup, diagnostic lookup, and template listing. Nesting: Mostly shallow, although diagnostic lookup and blueprint template listing introduce moderate nesting. Clarity of intent: Descriptive method names, a class docstring, and type annotations clarify behavior; however, rv and trv are cryptic, and unrelated score calculations distract from template loading. Code length: Generally concise, but unused calculations, unused imports, repeated verbose tuple annotations, and an avoidable inner loop add clutter. Action granularity: Each line generally performs one clear action. Reading flow: Methods follow a natural dispatch-and-helper pattern, with straightforward returns and exception handling; the inline import and irrelevant arithmetic interrupt that flow.

Run 2

Code Structure: Well-organized methods separate loader iteration, fast lookup, diagnostic lookup, and template listing. Nesting: Mostly shallow, although diagnostic lookup and template listing contain several nested levels. Clarity of intent: Descriptive method names, a class docstring, and type annotations communicate purpose; abbreviated variables such as rv, trv, and srcobj weaken clarity. The unrelated, unused score calculations are distracting, and App and Scaffold lack visible definitions or imports. Code length: Generally concise, but unused calculations, imports, repeated complex type annotations, and the template-listing loop add avoidable bulk. Action granularity: Statements consistently perform one action per line. Reading flow: Natural top-to-bottom organization and straightforward exception handling make execution easy to follow, though the local import and irrelevant calculations interrupt the diagnostic method.

Run 3

Code Structure: Well-organized class with separate methods for dispatch, diagnostic loading, fast loading, loader iteration, and template listing. Nesting: Mostly shallow, although template listing reaches three nested levels. Clarity of intent: Descriptive method names and type annotations clarify behavior, but abbreviations such as rv, trv, and srcobj obscure meaning. The unrelated, unused score calculations distract from template loading, and App and Scaffold lack visible definitions or imports. Code length: Generally concise, though repeated complex type annotations and the unnecessary calculations add clutter. Action granularity: Each line generally performs one action, making operations easy to follow. Reading flow: Public dispatch followed by helper implementations creates a logical progression; the mid-method import and unrelated calculations interrupt it.