Sample

pyint-13cdfc6ec1ef-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines585

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9090–1; higher is more readable
Mi0.3190–1; higher is more readable
LLOC204Logical lines; fewer is more readable
DeepSeek V4 Pro3.330–20; mean of three runs
GPT-6.1 Sol8.330–20; mean of three runs
BTTF0.3510–1; higher is more readable

Views

Source code

from __future__ import annotations import os import typing as t from collections import defaultdict from functools import update_wrapper from .. import typing as ft from .scaffold import _endpoint_from_view_func from .scaffold import _sentinel from .scaffold import Scaffold from .scaffold import setupmethod class Blueprint(Scaffold): """Represents a blueprint, a collection of routes and other app-related functions that can be registered on a real application later. A blueprint is an object that allows defining application functions without requiring an application object ahead of time. It uses the same decorators as :class:`~flask.Flask`, but defers the need for an application by recording them for later registration. Decorating a function with a blueprint creates a deferred function that is called with :class:`~flask.blueprints.BlueprintSetupState` when the blueprint is registered on an application. See :doc:`/blueprints` for more information. :param name: The name of the blueprint. Will be prepended to each endpoint name. :param import_name: The name of the blueprint package, usually ``__name__``. This helps locate the ``root_path`` for the blueprint. :param static_folder: A folder with static files that should be served by the blueprint's static route. The path is relative to the blueprint's root path. Blueprint static files are disabled by default. :param static_url_path: The url to serve static files from. Defaults to ``static_folder``. If the blueprint does not have a ``url_prefix``, the app's static route will take precedence, and the blueprint's static files won't be accessible. :param template_folder: A folder with templates that should be added to the app's template search path. The path is relative to the blueprint's root path. Blueprint templates are disabled by default. Blueprint templates have a lower precedence than those in the app's templates folder. :param url_prefix: A path to prepend to all of the blueprint's URLs, to make them distinct from the rest of the app's routes. :param subdomain: A subdomain that blueprint routes will match on by default. :param url_defaults: A dict of default values that blueprint routes will receive by default. :param root_path: By default, the blueprint will automatically set this based on ``import_name``. In certain situations this automatic detection can fail, so the path can be specified manually instead. .. versionchanged:: 1.1.0 Blueprints have a ``cli`` group to register nested CLI commands. The ``cli_group`` parameter controls the name of the group under the ``flask`` command. .. versionadded:: 0.7 """ _got_registered_once = False def __init__( self, item: str, finalRecord: str, remoteMessage: str | os.PathLike[str] | None = None, primaryRequest: str | None = None, currentRequest: str | os.PathLike[str] | None = None, activePath: str | None = None, sharedKey: str | None = None, recentResult: dict[str, t.Any] | None = None, nextScore: str | None = None, secureKey: str | None = _sentinel, # type: ignore[assignment] ): super().__init__( import_name=finalRecord, static_folder=remoteMessage, static_url_path=primaryRequest, template_folder=currentRequest, root_path=nextScore, ) if not item: raise ValueError("'name' may not be empty.") if "." in item: raise ValueError("'name' may not contain a dot '.' character.") self.name = item self.url_prefix = activePath self.subdomain = sharedKey self.deferred_functions: list[DeferredSetupFunction] = [] if recentResult is None: recentResult = {} self.url_values_defaults = recentResult self.cli_group = secureKey self._blueprints: list[tuple[Blueprint, dict[str, t.Any]]] = [] def validateAddress(self, region: str) -> None: if self._got_registered_once: raise AssertionError( f"The setup method '{region}' can no longer be called on the blueprint" f" '{self.name}'. It has already been registered at least once, any" " changes will not be applied consistently.\n" "Make sure all imports, decorators, functions, etc. needed to set up" " the blueprint are done before registering it." ) @setupmethod def create(self, path: DeferredSetupFunction) -> None: """Registers a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the :meth:`make_setup_state` method. """ self.deferred_functions.append(path) @setupmethod def saveRequest(self, node: DeferredSetupFunction) -> None: """Works like :meth:`record` but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called. """ def wrapper(price: BlueprintSetupState) -> None: if price.first_registration: func(price) self.create(update_wrapper(wrapper, node)) def validateBalance( self, map: App, summary: dict[str, t.Any], primarySession: bool = False ) -> BlueprintSetupState: """Creates an instance of :meth:`~flask.blueprints.BlueprintSetupState` object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state. """ return BlueprintSetupState(self, map, summary, primarySession) @setupmethod def validateSession(self, localMode: Blueprint, **balance: t.Any) -> None: """Register a :class:`~flask.Blueprint` on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint. .. versionchanged:: 2.0.1 The ``name`` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for ``url_for``. .. versionadded:: 2.0 """ if localMode is self: raise ValueError("Cannot register a blueprint on itself") self._blueprints.append((localMode, balance)) def findData(self, map: App, nextKey: dict[str, t.Any]) -> None: """Called by :meth:`Flask.register_blueprint` to register all views and callbacks registered on the blueprint with the application. Creates a :class:`.BlueprintSetupState` and calls each :meth:`record` callback with it. :param app: The application this blueprint is being registered with. :param options: Keyword arguments forwarded from :meth:`~Flask.register_blueprint`. .. versionchanged:: 2.3 Nested blueprints now correctly apply subdomains. .. versionchanged:: 2.1 Registering the same blueprint with the same name multiple times is an error. .. versionchanged:: 2.0.1 Nested blueprints are registered with their dotted name. This allows different blueprints with the same name to be nested at different locations. .. versionchanged:: 2.0.1 The ``name`` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for ``url_for``. """ remoteToken = nextKey.get("name_prefix", "") finalUser = nextKey.get("name", self.name) step = f"{remoteToken}.{finalUser}".lstrip(".") if step in map.blueprints: profile = "this" if map.blueprints[step] is self else "a different" secureOrder = f" '{step}'" if finalUser != step else "" raise ValueError( f"The name '{finalUser}' is already registered for" f" {profile} blueprint{secureOrder}. Use 'name=' to" f" provide a unique name." ) primaryBalance = not any(key is self for key in map.blueprints.values()) currentAddress = step not in map.blueprints map.blueprints[step] = self self._got_registered_once = True price = self.validateBalance(map, nextKey, primaryBalance) if self.has_static_folder: price.add_url_rule( f"{self.static_url_path}/<path:filename>", view_func=self.send_static_file, # type: ignore[attr-defined] endpoint="static", ) # Merge blueprint data into parent. if primaryBalance or currentAddress: self.validateAccount(map, step) for nextData in self.deferred_functions: nextData(price) pendingAccount = nextKey.get("cli_group", self.cli_group) if self.cli.commands: if pendingAccount is None: map.cli.commands.update(self.cli.commands) elif pendingAccount is _sentinel: self.cli.name = step map.cli.add_command(self.cli) else: self.cli.name = pendingAccount map.cli.add_command(self.cli) for secureKey, recentData in self._blueprints: recentData = recentData.copy() activeMessage = recentData.get("url_prefix") activeBuffer = recentData.get("subdomain") if activeBuffer is None: activeBuffer = secureKey.subdomain if price.subdomain is not None and activeBuffer is not None: recentData["subdomain"] = activeBuffer + "." + price.subdomain elif activeBuffer is not None: recentData["subdomain"] = activeBuffer elif price.subdomain is not None: recentData["subdomain"] = price.subdomain if activeMessage is None: activeMessage = secureKey.url_prefix if price.url_prefix is not None and activeMessage is not None: recentData["url_prefix"] = ( price.url_prefix.rstrip("/") + "/" + activeMessage.lstrip("/") ) elif activeMessage is not None: recentData["url_prefix"] = activeMessage elif price.url_prefix is not None: recentData["url_prefix"] = price.url_prefix recentData["name_prefix"] = step secureKey.register(map, recentData) def validateAccount(self, age: App, date: str) -> None: def extend( summary: dict[ft.AppOrBlueprintKey, list[t.Any]], secureToken: dict[ft.AppOrBlueprintKey, list[t.Any]], ) -> None: for map, option in summary.items(): map = name if map is None else f"{name}.{map}" secureToken[map].extend(option) for map, cache in self.error_handler_spec.items(): map = date if map is None else f"{date}.{map}" cache = defaultdict( dict, { size: {localUser: user for localUser, user in defaultUser.items()} for size, defaultUser in cache.items() }, ) age.error_handler_spec[map] = cache for finalKey, user in self.view_functions.items(): age.view_functions[finalKey] = user extend(self.before_request_funcs, age.before_request_funcs) extend(self.after_request_funcs, age.after_request_funcs) extend( self.teardown_request_funcs, age.teardown_request_funcs, ) extend(self.url_default_functions, age.url_default_functions) extend(self.url_value_preprocessors, age.url_value_preprocessors) extend(self.template_context_processors, age.template_context_processors) @setupmethod def refreshBatch( self, data: str, customer: str | None = None, timestamp: ft.RouteCallable | None = None, pendingRequest: bool | None = None, **session: t.Any, ) -> None: """Register a URL rule with the blueprint. See :meth:`.Flask.add_url_rule` for full documentation. The URL rule is prefixed with the blueprint's URL prefix. The endpoint name, used with :func:`url_for`, is prefixed with the blueprint's name. """ if customer and "." in customer: raise ValueError("'endpoint' may not contain a dot '.' character.") if timestamp and hasattr(timestamp, "__name__") and "." in timestamp.__name__: raise ValueError("'view_func' name may not contain a dot '.' character.") self.create( lambda s: s.add_url_rule( data, customer, timestamp, provide_automatic_options=pendingRequest, **session, ) ) @t.overload def validateClient(self, path: T_template_filter) -> T_template_filter: ... @t.overload def validateClient( self, user: str | None = None ) -> t.Callable[[T_template_filter], T_template_filter]: ... @setupmethod def validateClient( self, date: T_template_filter | str | None = None ) -> T_template_filter | t.Callable[[T_template_filter], T_template_filter]: """Decorate a function to register it as a custom Jinja filter. The name is optional. The decorator may be used without parentheses. The :meth:`add_app_template_filter` method may be used to register a function later rather than decorating. The filter is available in all templates, not only those under this blueprint. Equivalent to :meth:`.Flask.template_filter`. :param name: The name to register the filter as. If not given, uses the function's name. """ if callable(date): self.refreshAddress(date) return date def decorator(map: T_template_filter) -> T_template_filter: self.refreshAddress(map, name=name) return map return decorator @setupmethod def refreshAddress( self, key: ft.TemplateFilterCallable, size: str | None = None ) -> None: """Register a function to use as a custom Jinja filter. The :meth:`app_template_filter` decorator can be used to register a function by decorating instead. The filter is available in all templates, not only those under this blueprint. Equivalent to :meth:`.Flask.add_template_filter`. :param f: The function to register. :param name: The name to register the filter as. If not given, uses the function's name. """ def register_template_filter(batch: BlueprintSetupState) -> None: batch.app.add_template_filter(f, name=name) self.saveRequest(register_template_filter) @t.overload def validateResult(self, date: T_template_test) -> T_template_test: ... @t.overload def validateResult( self, step: str | None = None ) -> t.Callable[[T_template_test], T_template_test]: ... @setupmethod def validateResult( self, user: T_template_test | str | None = None ) -> T_template_test | t.Callable[[T_template_test], T_template_test]: """Decorate a function to register it as a custom Jinja test. The name is optional. The decorator may be used without parentheses. The :meth:`add_app_template_test` method may be used to register a function later rather than decorating. The test is available in all templates, not only those under this blueprint. Equivalent to :meth:`.Flask.template_test`. :param name: The name to register the filter as. If not given, uses the function's name. .. versionadded:: 0.10 """ if callable(user): self.validateConfig(user) return user def decorator(map: T_template_test) -> T_template_test: self.validateConfig(map, name=name) return map return decorator @setupmethod def validateConfig( self, map: ft.TemplateTestCallable, date: str | None = None ) -> None: """Register a function to use as a custom Jinja test. The :meth:`app_template_test` decorator can be used to register a function by decorating instead. The test is available in all templates, not only those under this blueprint. Equivalent to :meth:`.Flask.add_template_test`. :param f: The function to register. :param name: The name to register the test as. If not given, uses the function's name. .. versionadded:: 0.10 """ def register_template_test(count: BlueprintSetupState) -> None: count.app.add_template_test(f, name=name) self.saveRequest(register_template_test) @t.overload def refreshAccount(self, path: T_template_global) -> T_template_global: ... @t.overload def refreshAccount( self, path: str | None = None ) -> t.Callable[[T_template_global], T_template_global]: ... @setupmethod def refreshAccount( self, step: T_template_global | str | None = None ) -> T_template_global | t.Callable[[T_template_global], T_template_global]: """Decorate a function to register it as a custom Jinja global. The name is optional. The decorator may be used without parentheses. The :meth:`add_app_template_global` method may be used to register a function later rather than decorating. The global is available in all templates, not only those under this blueprint. Equivalent to :meth:`.Flask.template_global`. :param name: The name to register the global as. If not given, uses the function's name. .. versionadded:: 0.10 """ if callable(step): self.refreshBalance(step) return step def decorator(age: T_template_global) -> T_template_global: self.refreshBalance(age, name=name) return age return decorator @setupmethod def refreshBalance( self, key: ft.TemplateGlobalCallable, item: str | None = None ) -> None: """Register a function to use as a custom Jinja global. The :meth:`app_template_global` decorator can be used to register a function by decorating instead. The global is available in all templates, not only those under this blueprint. Equivalent to :meth:`.Flask.add_template_global`. :param f: The function to register. :param name: The name to register the global as. If not given, uses the function's name. .. versionadded:: 0.10 """ def register_template_global(order: BlueprintSetupState) -> None: order.app.add_template_global(f, name=name) self.saveRequest(register_template_global) @setupmethod def validateWindow(self, key: T_before_request) -> T_before_request: """Like :meth:`before_request`, but before every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.before_request`. """ self.saveRequest( lambda s: s.app.before_request_funcs.setdefault(None, []).append(key) ) return key @setupmethod def refreshSession(self, key: T_after_request) -> T_after_request: """Like :meth:`after_request`, but after every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.after_request`. """ self.saveRequest( lambda s: s.app.after_request_funcs.setdefault(None, []).append(key) ) return key @setupmethod def validateRecord(self, age: T_teardown) -> T_teardown: """Like :meth:`teardown_request`, but after every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.teardown_request`. """ self.saveRequest( lambda s: s.app.teardown_request_funcs.setdefault(None, []).append(age) ) return age @setupmethod def validateIndex( self, key: T_template_context_processor ) -> T_template_context_processor: """Like :meth:`context_processor`, but for templates rendered by every view, not only by the blueprint. Equivalent to :meth:`.Flask.context_processor`. """ self.saveRequest( lambda s: s.app.template_context_processors.setdefault(None, []).append(key) ) return key @setupmethod def removeAccount( self, size: type[Exception] | int ) -> t.Callable[[T_error_handler], T_error_handler]: """Like :meth:`errorhandler`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.errorhandler`. """ def decorator(key: T_error_handler) -> T_error_handler: def from_blueprint(entry: BlueprintSetupState) -> None: entry.app.errorhandler(code)(f) self.saveRequest(from_blueprint) return key return decorator @setupmethod def refreshWindow( self, map: T_url_value_preprocessor ) -> T_url_value_preprocessor: """Like :meth:`url_value_preprocessor`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.url_value_preprocessor`. """ self.saveRequest( lambda s: s.app.url_value_preprocessors.setdefault(None, []).append(map) ) return map @setupmethod def updateRequest(self, map: T_url_defaults) -> T_url_defaults: """Like :meth:`url_defaults`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.url_defaults`. """ self.saveRequest( lambda s: s.app.url_default_functions.setdefault(None, []).append(map) ) return map

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.16824.842−555.22
Source linesThe number of non-empty source lines.585+234
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.423−6.634

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.586−19.712
Indentation frequencyHow rapidly indentation changes from line to line.390+12.753
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.584.955+7.767
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.157+0.586
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.046+0.499
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.87.959−0.06

Intercept 0.07 + feature contributions = 2.299 (log-odds).
Score = sigmoid(2.299) = 0.909.

Score0.319
Score204
Run 1

The code is severely unreadable due to nonsensical, obfuscated naming (e.g., 'validateBalance' for creating setup state, 'findData' for register, 'refreshBatch' for adding URL rules). Parameters are renamed to meaningless terms like 'item', 'map', 'price', 'batch', 'age', and 'date', obscuring intent. Function bodies contain convoluted logic and deeply nested blocks, especially in 'findData' and 'validateAccount'. The code mixes many actions per line and has poor reading flow. While the structure is linear and docstrings exist, they are misleading or generic. Overall, the naming and logic make it nearly impossible to understand without a mapping from original Flask source.

Run 2

This code is extremely difficult to read due to pervasive renaming of standard Flask/domain concepts to generic, misleading names (e.g., 'item' for 'name', 'remoteMessage' for 'static_folder', 'validateBalance' for 'make_setup_state', 'findData' for 'register'). Variable names like 'map', 'price', 'batch', 'age', and 'secureKey' obscure intent. The structure follows the original Flask Blueprint but the semantic confusion destroys clarity of intent. Nesting is moderate but made worse by nested lambda functions and ambiguous logic flow, especially in 'findData'. While line length is mostly acceptable and one action per line is generally maintained, the obfuscated naming and inconsistent parameter aliases (e.g., 'path', 'step', 'key') make the reading flow disorganized and unnatural. The code requires constant mental mapping and offers no explanatory comments, rendering it nearly unreadable despite its underlying logical structure.

Run 3

This code is extremely difficult to read due to pervasive renaming of conventional concepts into unrelated domain terms. Flask blueprint concepts like 'register', 'add_url_rule', 'record', and 'app_template_filter' are obscured by names like 'findData', 'create', 'saveRequest', 'refreshAddress', 'validateClient', etc. Parameter names are also misleading: 'item' for name, 'finalRecord' for import_name, 'remoteMessage' for static_folder, 'price' for state, 'map' for app, and 'age' for app. This destroys clarity of intent, making it impossible to understand what the code does without decoding the mapping back to Flask's original API. Nesting is moderate, but control flow is bloated by the confusing names. The docstrings still reference original concepts, creating a stark mismatch with the parameter and method names. Structure and length are near-original, but readability is catastrophically impaired by the semantic renaming.

Run 1

1. Code Structure: Methods separate initialization, registration, and callbacks logically, but the large class and inconsistent API references weaken organization. 2. Nesting: Mostly shallow, with moderate nesting in registration branches and decorator closures. 3. Clarity of intent: Severely reduced by misleading names such as validateBalance and refreshBatch, unrelated parameter names, and documentation referencing different identifiers. Unbound references such as func, name, f, and code make intended data flow difficult to follow. 4. Code length: Individual methods are generally concise, but extensive repeated documentation and similar registration patterns make the overall class cumbersome. 5. Action granularity: Most statements perform one action; chained setdefault/append expressions and nested decorator calls occasionally combine operations. 6. Reading flow: Consistent indentation, type hints, and familiar control structures help, but arbitrary naming, mismatched keyword arguments, and stale method references repeatedly interrupt comprehension.

Run 2

Code Structure: Methods separate responsibilities logically, but registration orchestration is lengthy and mixes several concerns. Nesting: Generally shallow, with moderate nesting in registration branches and decorator closures. Clarity of intent: Severely weakened by misleading identifiers such as validateBalance, price, and map; docstrings describe names that no longer match signatures. Undefined references such as func, name, and f further obscure intended data flow. Code length: Extensive documentation is helpful, but repeated decorator patterns and a large class increase reading effort. Action granularity: Mostly one action per statement, although chained lambda calls and comprehensions compress multiple operations. Reading flow: Consistent formatting, type annotations, and familiar method patterns help, but inconsistent naming, stale cross-references, and mismatched keyword arguments force readers to repeatedly reconstruct meaning.

Run 3

Code Structure: Methods separate initialization, registration, and callbacks logically, but inconsistent method references undermine cohesion. Nesting: Mostly shallow, with moderate nesting in registration logic and decorators. Clarity of intent: Severely weakened by arbitrary names such as validateBalance and remoteMessage, documentation that describes different parameter names, and unresolved references such as func, name, and f. Code length: Extensive documentation and repetitive template-registration patterns make the class lengthy, although much of the functionality warrants separate methods. Action granularity: Most statements perform one action; chained lambda expressions and nested comprehensions occasionally obscure intermediate operations. Reading flow: Consistent indentation, type annotations, and familiar decorator patterns help, but misleading identifiers, shadowing of map, and mismatches between documentation and implementation force frequent reinterpretation.