Sample

pyint-b59ad93a93de-I01

Remove comments and docstrings

Matched original source

Lines393

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9920–1; higher is more readable
Mi0.5260–1; higher is more readable
LLOC184Logical lines; fewer is more readable
DeepSeek V4 Pro140–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3620–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): _got_registered_once = False def __init__( self, name: str, import_name: str, static_folder: str | os.PathLike[str] | None = None, static_url_path: str | None = None, template_folder: str | os.PathLike[str] | None = None, url_prefix: str | None = None, subdomain: str | None = None, url_defaults: dict[str, t.Any] | None = None, root_path: str | None = None, cli_group: str | None = _sentinel, ): super().__init__( import_name=import_name, static_folder=static_folder, static_url_path=static_url_path, template_folder=template_folder, root_path=root_path, ) if not name: raise ValueError("'name' may not be empty.") if "." in name: raise ValueError("'name' may not contain a dot '.' character.") self.name = name self.url_prefix = url_prefix self.subdomain = subdomain self.deferred_functions: list[DeferredSetupFunction] = [] if url_defaults is None: url_defaults = {} self.url_values_defaults = url_defaults self.cli_group = cli_group self._blueprints: list[tuple[Blueprint, dict[str, t.Any]]] = [] def _check_setup_finished(self, f_name: str) -> None: if self._got_registered_once: raise AssertionError( f"The setup method '{f_name}' 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 record(self, func: DeferredSetupFunction) -> None: self.deferred_functions.append(func) @setupmethod def record_once(self, func: DeferredSetupFunction) -> None: def wrapper(state: BlueprintSetupState) -> None: if state.first_registration: func(state) self.record(update_wrapper(wrapper, func)) def make_setup_state( self, app: App, options: dict[str, t.Any], first_registration: bool = False ) -> BlueprintSetupState: return BlueprintSetupState(self, app, options, first_registration) @setupmethod def register_blueprint(self, blueprint: Blueprint, **options: t.Any) -> None: if blueprint is self: raise ValueError("Cannot register a blueprint on itself") self._blueprints.append((blueprint, options)) def register(self, app: App, options: dict[str, t.Any]) -> None: name_prefix = options.get("name_prefix", "") self_name = options.get("name", self.name) name = f"{name_prefix}.{self_name}".lstrip(".") if name in app.blueprints: bp_desc = "this" if app.blueprints[name] is self else "a different" existing_at = f" '{name}'" if self_name != name else "" raise ValueError( f"The name '{self_name}' is already registered for" f" {bp_desc} blueprint{existing_at}. Use 'name=' to" f" provide a unique name." ) first_bp_registration = not any(bp is self for bp in app.blueprints.values()) first_name_registration = name not in app.blueprints app.blueprints[name] = self self._got_registered_once = True state = self.make_setup_state(app, options, first_bp_registration) if self.has_static_folder: state.add_url_rule( f"{self.static_url_path}/<path:filename>", view_func=self.send_static_file, endpoint="static", ) if first_bp_registration or first_name_registration: self._merge_blueprint_funcs(app, name) for deferred in self.deferred_functions: deferred(state) cli_resolved_group = options.get("cli_group", self.cli_group) if self.cli.commands: if cli_resolved_group is None: app.cli.commands.update(self.cli.commands) elif cli_resolved_group is _sentinel: self.cli.name = name app.cli.add_command(self.cli) else: self.cli.name = cli_resolved_group app.cli.add_command(self.cli) for blueprint, bp_options in self._blueprints: bp_options = bp_options.copy() bp_url_prefix = bp_options.get("url_prefix") bp_subdomain = bp_options.get("subdomain") if bp_subdomain is None: bp_subdomain = blueprint.subdomain if state.subdomain is not None and bp_subdomain is not None: bp_options["subdomain"] = bp_subdomain + "." + state.subdomain elif bp_subdomain is not None: bp_options["subdomain"] = bp_subdomain elif state.subdomain is not None: bp_options["subdomain"] = state.subdomain if bp_url_prefix is None: bp_url_prefix = blueprint.url_prefix if state.url_prefix is not None and bp_url_prefix is not None: bp_options["url_prefix"] = ( state.url_prefix.rstrip("/") + "/" + bp_url_prefix.lstrip("/") ) elif bp_url_prefix is not None: bp_options["url_prefix"] = bp_url_prefix elif state.url_prefix is not None: bp_options["url_prefix"] = state.url_prefix bp_options["name_prefix"] = name blueprint.register(app, bp_options) def _merge_blueprint_funcs(self, app: App, name: str) -> None: def extend( bp_dict: dict[ft.AppOrBlueprintKey, list[t.Any]], parent_dict: dict[ft.AppOrBlueprintKey, list[t.Any]], ) -> None: for key, values in bp_dict.items(): key = name if key is None else f"{name}.{key}" parent_dict[key].extend(values) for key, value in self.error_handler_spec.items(): key = name if key is None else f"{name}.{key}" value = defaultdict( dict, { code: {exc_class: func for exc_class, func in code_values.items()} for code, code_values in value.items() }, ) app.error_handler_spec[key] = value for endpoint, func in self.view_functions.items(): app.view_functions[endpoint] = func extend(self.before_request_funcs, app.before_request_funcs) extend(self.after_request_funcs, app.after_request_funcs) extend( self.teardown_request_funcs, app.teardown_request_funcs, ) extend(self.url_default_functions, app.url_default_functions) extend(self.url_value_preprocessors, app.url_value_preprocessors) extend(self.template_context_processors, app.template_context_processors) @setupmethod def add_url_rule( self, rule: str, endpoint: str | None = None, view_func: ft.RouteCallable | None = None, provide_automatic_options: bool | None = None, **options: t.Any, ) -> None: if endpoint and "." in endpoint: raise ValueError("'endpoint' may not contain a dot '.' character.") if view_func and hasattr(view_func, "__name__") and "." in view_func.__name__: raise ValueError("'view_func' name may not contain a dot '.' character.") self.record( lambda s: s.add_url_rule( rule, endpoint, view_func, provide_automatic_options=provide_automatic_options, **options, ) ) @t.overload def app_template_filter(self, name: T_template_filter) -> T_template_filter: ... @t.overload def app_template_filter( self, name: str | None = None ) -> t.Callable[[T_template_filter], T_template_filter]: ... @setupmethod def app_template_filter( self, name: T_template_filter | str | None = None ) -> T_template_filter | t.Callable[[T_template_filter], T_template_filter]: if callable(name): self.add_app_template_filter(name) return name def decorator(f: T_template_filter) -> T_template_filter: self.add_app_template_filter(f, name=name) return f return decorator @setupmethod def add_app_template_filter( self, f: ft.TemplateFilterCallable, name: str | None = None ) -> None: def register_template_filter(state: BlueprintSetupState) -> None: state.app.add_template_filter(f, name=name) self.record_once(register_template_filter) @t.overload def app_template_test(self, name: T_template_test) -> T_template_test: ... @t.overload def app_template_test( self, name: str | None = None ) -> t.Callable[[T_template_test], T_template_test]: ... @setupmethod def app_template_test( self, name: T_template_test | str | None = None ) -> T_template_test | t.Callable[[T_template_test], T_template_test]: if callable(name): self.add_app_template_test(name) return name def decorator(f: T_template_test) -> T_template_test: self.add_app_template_test(f, name=name) return f return decorator @setupmethod def add_app_template_test( self, f: ft.TemplateTestCallable, name: str | None = None ) -> None: def register_template_test(state: BlueprintSetupState) -> None: state.app.add_template_test(f, name=name) self.record_once(register_template_test) @t.overload def app_template_global(self, name: T_template_global) -> T_template_global: ... @t.overload def app_template_global( self, name: str | None = None ) -> t.Callable[[T_template_global], T_template_global]: ... @setupmethod def app_template_global( self, name: T_template_global | str | None = None ) -> T_template_global | t.Callable[[T_template_global], T_template_global]: if callable(name): self.add_app_template_global(name) return name def decorator(f: T_template_global) -> T_template_global: self.add_app_template_global(f, name=name) return f return decorator @setupmethod def add_app_template_global( self, f: ft.TemplateGlobalCallable, name: str | None = None ) -> None: def register_template_global(state: BlueprintSetupState) -> None: state.app.add_template_global(f, name=name) self.record_once(register_template_global) @setupmethod def before_app_request(self, f: T_before_request) -> T_before_request: self.record_once( lambda s: s.app.before_request_funcs.setdefault(None, []).append(f) ) return f @setupmethod def after_app_request(self, f: T_after_request) -> T_after_request: self.record_once( lambda s: s.app.after_request_funcs.setdefault(None, []).append(f) ) return f @setupmethod def teardown_app_request(self, f: T_teardown) -> T_teardown: self.record_once( lambda s: s.app.teardown_request_funcs.setdefault(None, []).append(f) ) return f @setupmethod def app_context_processor( self, f: T_template_context_processor ) -> T_template_context_processor: self.record_once( lambda s: s.app.template_context_processors.setdefault(None, []).append(f) ) return f @setupmethod def app_errorhandler( self, code: type[Exception] | int ) -> t.Callable[[T_error_handler], T_error_handler]: def decorator(f: T_error_handler) -> T_error_handler: def from_blueprint(state: BlueprintSetupState) -> None: state.app.errorhandler(code)(f) self.record_once(from_blueprint) return f return decorator @setupmethod def app_url_value_preprocessor( self, f: T_url_value_preprocessor ) -> T_url_value_preprocessor: self.record_once( lambda s: s.app.url_value_preprocessors.setdefault(None, []).append(f) ) return f @setupmethod def app_url_defaults(self, f: T_url_defaults) -> T_url_defaults: self.record_once( lambda s: s.app.url_default_functions.setdefault(None, []).append(f) ) return f

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.16048.702−529.607
Source linesThe number of non-empty source lines.393+157.2
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.336−6.504

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.393−12.879
Indentation frequencyHow rapidly indentation changes from line to line.393+12.856
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.392.932+5.083
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
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.168
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.86.934−0.017

Intercept 0.07 + feature contributions = 4.875 (log-odds).
Score = sigmoid(4.875) = 0.992.

Score0.526
Score184
Run 1

The code is well-structured at the class level with clear method names and type hints, indicating professional Flask internals. However, several methods like `register` and `_merge_blueprint_funcs` are very long and contain multiple logical actions, reducing readability. Nesting is moderate but `register` has deep conditional chains. The intent is generally clear, especially for decorators, but complex state-manipulation logic in `register` is hard to follow. Code length is unnecessarily long in some methods, and action granularity is mixed—some lines pack many operations. Reading flow is natural for simple methods but jarring in the large ones. Overall, it's understandable for an experienced Flask developer but could benefit from decomposition into smaller helper methods.

Run 2

The code is moderately readable, with clear method names and type hints, but suffers from several issues. Structure is logical (Flask Blueprint pattern) but some methods like register() and _merge_blueprint_funcs are long and do many things. Nesting is mostly flat except for loops and conditionals, which remain manageable. Clarity of intent is mixed—simple decorators are obvious, but complex logic (e.g., blueprint registration, prefix merging) is less explicit. Code length is acceptable for the file but could be reduced with helper functions. Action granularity often combines multiple actions per line in complex branches, harming readability. Reading flow is natural in simple methods but becomes disjointed in register() and _merge_blueprint_funcs due to dense processing and repetitive patterns. Overall, it reads like a mature framework module: clear for those familiar with Flask internals, but not immediately approachable for newcomers.

Run 3

The code is generally well-structured with clear class organization and type hints, but readability is hindered by several factors. The register method is quite long and contains complex conditional logic that could benefit from extraction into helper methods. Nesting is moderate but manageable. Intent is mostly clear with descriptive method names and docstrings (though some empty docstrings exist). Code length is excessive for certain methods like register() and _merge_blueprint_funcs(). Action granularity is mostly good with one operation per line. Reading flow is natural within methods but jumps between many different concerns. The use of type aliases and imports is clean, though some naming could be more explicit. Overall, it's readable for experienced Flask developers but could be improved with better modularization and more focused methods.

Run 1

Code Structure: Methods are logically grouped around blueprint setup, registration, and application hooks, although register handles several responsibilities. Nesting: Mostly shallow, with moderate branching in registration and a few nested decorator functions. Clarity of intent: Descriptive method names, type annotations, and explicit validation messages communicate purpose well; missing docstrings and unexplained deferred-registration semantics make some behavior harder to understand. Code length: Individual helpers are concise, but repeated template-registration patterns, verbose overloads, and the long register method increase reading effort. Action granularity: Generally one action per statement, though chained setdefault/append calls and nested comprehensions combine operations. Reading flow: Consistent naming and predictable decorator patterns support natural reading; excessive blank whitespace, dense typing declarations, and reliance on external framework types interrupt it.

Run 2

Code Structure: Methods are logically grouped around blueprint setup, registration, and application hooks, with useful helper extraction. Nesting: Most methods are shallow; registration branches, nested decorators, and dictionary comprehensions add moderate complexity. Clarity of intent: Descriptive method names and extensive type annotations communicate purpose, but missing documentation and externally defined types make deferred registration semantics harder to understand. Code length: Individual helpers are concise, although repeated decorator patterns and the lengthy register method increase reading effort. Action granularity: Most statements perform one action; chained setdefault/append calls and registration lambdas compress multiple operations. Reading flow: Initialization followed by registration and hook methods provides a natural progression, but overload declarations, excessive blank whitespace, and switching between immediate and deferred execution occasionally interrupt it.

Run 3

Code Structure: Methods are logically grouped around blueprint initialization, registration, and application hooks, although register handles several responsibilities. Nesting: Most methods are flat; registration branches, nested decorators, and comprehensions introduce moderate complexity. Clarity of intent: Descriptive method names and type annotations communicate purpose, but absent docstrings and externally defined types make deferred registration semantics harder to understand independently. Code length: Individual helpers are concise, but repeated template registration patterns and lengthy registration logic increase overall length. Action granularity: Statements generally perform one action each; chained setdefault/append calls and deferred lambdas compress multiple operations. Reading flow: Consistent naming and predictable decorator patterns support navigation, while excess blank lines, dense overload declarations, and context-dependent callbacks occasionally interrupt the flow.