Sample

pyint-dbf864a1fba1-I04

Replace names with deterministic minifier-style shortest identifiers

Matched original source

Lines326

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4540–1; higher is more readable
Mi0.4910–1; higher is more readable
LLOC99Logical lines; fewer is more readable
DeepSeek V4 Pro30–20; mean of three runs
GPT-6.1 Sol110–20; mean of three runs
BTTF0.4510–1; higher is more readable

Views

Source code

from __future__ import annotations import errno import json import os import types import typing as t from werkzeug.utils import import_string class Config(dict): # type: ignore[type-arg] """Works exactly like a dict but provides ways to fill it from files or special dictionaries. There are two common patterns to populate the config. Either you can fill the config from a config file:: app.config.from_pyfile('yourconfig.cfg') Or alternatively you can define the configuration options in the module that calls :meth:`from_object` or provide an import path to a module that should be loaded. It is also possible to tell it to use the same module and with that provide the configuration values just before the call:: DEBUG = True SECRET_KEY = 'development key' app.config.from_object(__name__) In both cases (loading from any Python file or loading from modules), only uppercase keys are added to the config. This makes it possible to use lowercase values in the config file for temporary values that are not added to the config or to define the config keys in the same file that implements the application. Probably the most interesting way to load configurations is from an environment variable pointing to a file:: app.config.from_envvar('YOURAPPLICATION_SETTINGS') In this case before launching the application you have to set this environment variable to the file you want to use. On Linux and OS X use the export statement:: export YOURAPPLICATION_SETTINGS='/path/to/config/file' On windows use `set` instead. :param root_path: path to which files are read relative from. When the config object is created by the application, this is the application's :attr:`~flask.Flask.root_path`. :param defaults: an optional dictionary of default values """ def __init__( self, l: str | os.PathLike[str], m: dict[str, t.Any] | None = None, ) -> None: super().__init__(m or {}) self.root_path = l def a(self, n: str, o: bool = False) -> bool: """Loads a configuration from an environment variable pointing to a configuration file. This is basically just a shortcut with nicer error messages for this line of code:: app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS']) :param variable_name: name of the environment variable :param silent: set to ``True`` if you want silent failure for missing files. :return: ``True`` if the file was loaded successfully. """ p = os.environ.get(n) if not p: if o: return False raise RuntimeError( f"The environment variable {n!r} is not set" " and as such configuration could not be loaded. Set" " this variable and make it point to a configuration" " file" ) return self.c(p, silent=o) def b( self, q: str = "FLASK", *, r: t.Callable[[str], t.Any] = json.loads ) -> bool: """Load any environment variables that start with ``FLASK_``, dropping the prefix from the env key for the config key. Values are passed through a loading function to attempt to convert them to more specific types than strings. Keys are loaded in :func:`sorted` order. The default loading function attempts to parse values as any valid JSON type, including dicts and lists. Specific items in nested dicts can be set by separating the keys with double underscores (``__``). If an intermediate key doesn't exist, it will be initialized to an empty dict. :param prefix: Load env vars that start with this prefix, separated with an underscore (``_``). :param loads: Pass each string value to this function and use the returned value as the config value. If any error is raised it is ignored and the value remains a string. The default is :func:`json.loads`. .. versionadded:: 2.1 """ q = f"{q}_" for s in sorted(os.environ): if not s.startswith(q): continue u = os.environ[s] s = s.removeprefix(q) try: u = r(u) except Exception: # Keep the value as a string if loading failed. pass if "__" not in s: # A non-nested key, set directly. self[s] = u continue # Traverse nested dictionaries with keys separated by "__". w = self *x, y = s.split("__") for z in x: # If an intermediate dict does not exist, create it. if z not in w: w[z] = {} w = w[z] w[y] = u return True def c( self, A: str | os.PathLike[str], B: bool = False ) -> bool: """Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the :meth:`from_object` function. :param filename: the filename of the config. This can either be an absolute filename or a filename relative to the root path. :param silent: set to ``True`` if you want silent failure for missing files. :return: ``True`` if the file was loaded successfully. .. versionadded:: 0.7 `silent` parameter. """ A = os.path.join(self.root_path, A) C = types.ModuleType("config") C.__file__ = A try: with open(A, mode="rb") as D: exec(compile(D.read(), A, "exec"), C.__dict__) except OSError as e: if B and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR): return False e.strerror = f"Unable to load configuration file ({e.strerror})" raise self.g(C) return True def g(self, E: object | str) -> None: """Updates the values from the given object. An object can be of one of the following two types: - a string: in this case the object with that name will be imported - an actual object reference: that object is used directly Objects are usually either modules or classes. :meth:`from_object` loads only the uppercase attributes of the module/class. A ``dict`` object will not work with :meth:`from_object` because the keys of a ``dict`` are not attributes of the ``dict`` class. Example of module-based configuration:: app.config.from_object('yourapplication.default_config') from yourapplication import default_config app.config.from_object(default_config) Nothing is done to the object before loading. If the object is a class and has ``@property`` attributes, it needs to be instantiated before being passed to this method. You should not use this function to load the actual configuration but rather configuration defaults. The actual config should be loaded with :meth:`from_pyfile` and ideally from a location not within the package because the package might be installed system wide. See :ref:`config-dev-prod` for an example of class-based configuration using :meth:`from_object`. :param obj: an import name or object """ if isinstance(E, str): E = import_string(E) for F in dir(E): if F.isupper(): self[F] = getattr(E, F) def h( self, G: str | os.PathLike[str], H: t.Callable[[t.IO[t.Any]], t.Mapping[str, t.Any]], I: bool = False, J: bool = True, ) -> bool: """Update the values in the config from a file that is loaded using the ``load`` parameter. The loaded data is passed to the :meth:`from_mapping` method. .. code-block:: python import json app.config.from_file("config.json", load=json.load) import tomllib app.config.from_file("config.toml", load=tomllib.load, text=False) :param filename: The path to the data file. This can be an absolute path or relative to the config root path. :param load: A callable that takes a file handle and returns a mapping of loaded data from the file. :type load: ``Callable[[Reader], Mapping]`` where ``Reader`` implements a ``read`` method. :param silent: Ignore the file if it doesn't exist. :param text: Open the file in text or binary mode. :return: ``True`` if the file was loaded successfully. .. versionchanged:: 2.3 The ``text`` parameter was added. .. versionadded:: 2.0 """ G = os.path.join(self.root_path, G) try: with open(G, "r" if J else "rb") as K: L = H(K) except OSError as e: if I and e.errno in (errno.ENOENT, errno.EISDIR): return False e.strerror = f"Unable to load configuration file ({e.strerror})" raise return self.i(L) def i( self, M: t.Mapping[str, t.Any] | None = None, **N: t.Any ) -> bool: """Updates the config like :meth:`update` ignoring items with non-upper keys. :return: Always returns ``True``. .. versionadded:: 0.11 """ O: dict[str, t.Any] = {} if M is not None: O.update(M) O.update(N) for P, Q in O.items(): if P.isupper(): self[P] = Q return True def j( self, R: str, S: bool = True, T: bool = True ) -> dict[str, t.Any]: """Returns a dictionary containing a subset of configuration options that match the specified namespace/prefix. Example usage:: app.config['IMAGE_STORE_TYPE'] = 'fs' app.config['IMAGE_STORE_PATH'] = '/var/app/images' app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com' image_store_config = app.config.get_namespace('IMAGE_STORE_') The resulting dictionary `image_store_config` would look like:: { 'type': 'fs', 'path': '/var/app/images', 'base_url': 'http://img.website.com' } This is often useful when configuration options map directly to keyword arguments in functions or class constructors. :param namespace: a configuration namespace :param lowercase: a flag indicating if the keys of the resulting dictionary should be lowercase :param trim_namespace: a flag indicating if the keys of the resulting dictionary should not include the namespace .. versionadded:: 0.11 """ U = {} for V, W in self.items(): if not V.startswith(R): continue if T: X = V[len(R) :] else: X = V if S: X = X.lower() U[X] = W return U def __repr__(self) -> str: return f"<{type(self).__name__} {dict.__repr__(self)}>"

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.5827.841−192.319
Source linesThe number of non-empty source lines.326+130.4
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.37−6.555

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.326−10.506
Indentation frequencyHow rapidly indentation changes from line to line.147+4.347
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.325.8+4.144
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.032+0.635
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.75.162+0.408
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.78.963+0.321

Intercept 0.07 + feature contributions = -0.183 (log-odds).
Score = sigmoid(-0.183) = 0.454.

Score0.491
Score99
Run 1

The code is largely unreadable due to cryptic single-letter parameter and variable names (e.g., l, m, a, n, o, p, c, B, A, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X). While docstrings remain descriptive, the implementation itself obscures intent, violating clarity of intent. The nested traversal in the environment variable loader uses multiple temporary variables and inline dict creation, increasing cognitive load. Action granularity is mostly one action per line, but the pervasive meaningless names negate this benefit. Code length is moderate but feels longer due to poor naming. Reading flow is severely disrupted because readers must constantly map letters to meanings. Structure is logical, but the variable naming alone renders the code nearly unreadable. Overall, the implementation is functional but extremely developer-hostile.

Run 2

The code suffers from severe readability issues due to meaningless parameter names (e.g., 'l', 'm', 'a', 'b', 'g', 'i') that obscure intent despite verbose docstrings describing proper names. Method names are also obfuscated, making the API incomprehensible without docstring reverse-engineering. While structure is mostly flat and action granularity is reasonable, the jarring contrast between clear, well-written prose in docstrings and cryptic identifiers destroys reading flow and clarity. The class is relatively concise, but this concision comes at the cost of self-documenting code. Renaming methods and parameters to match documented semantics would dramatically improve readability.

Run 3

The code is extremely difficult to read due to systematically obfuscated identifiers (e.g., 'a', 'b', 'c', 'l', 'm', 'n', 'o', 'p', 'q', 'r') that replace all meaningful method and parameter names. This destroys clarity of intent, making it impossible to understand what each method does without reading docstrings or tracing variable assignments. The docstrings contain the original meaningful names, but the code itself is a tangle of single-letter variables. Nesting and structure are mostly intact, but the obfuscated names break reading flow and action granularity, forcing readers to constantly map cryptic names back to docstrings. The code length is moderate and structure is logical, but these factors are overwhelmed by the lack of semantic naming.

Run 1

Code Structure: Configuration-loading responsibilities are logically separated into small methods within one cohesive class. Nesting: Mostly shallow, with early returns and continue statements keeping control flow manageable; nested environment-key traversal adds modest complexity. Clarity of intent: Single-letter method and variable names severely obscure purpose. Detailed docstrings help, but reference original method and parameter names that no longer match the implementation, making navigation confusing. Code length: Executable logic is reasonably concise, although extensive documentation dominates the listing and increases reading effort. Action granularity: Most lines perform one clear operation; the combined read, compile, and exec expression is denser. Reading flow: Consistent formatting, type annotations, and conventional exception handling support readability, but opaque identifiers and mismatched documentation repeatedly interrupt understanding.

Run 2

Code Structure: A cohesive configuration class separates loading and filtering operations into focused methods. Nesting: Generally shallow, with early returns and continue statements; nested environment-key traversal adds moderate complexity. Clarity of intent: Severely weakened by single-letter method and variable names. Docstrings explain functionality, but reference original method and parameter names that do not match the implementation, making navigation confusing. Code length: Implementations are reasonably concise, although extensive documentation dominates the file and includes distracting historical details. Action granularity: Most lines perform one operation; a few expressions combine reading, compilation, and execution. Reading flow: Consistent formatting, type annotations, comments, and conventional control flow help, but opaque identifiers and mismatched documentation force repeated cross-referencing.

Run 3

Code Structure: Configuration-loading responsibilities are logically separated into methods, but opaque method names obscure their relationships. Nesting: Mostly shallow, with early returns and continue statements; nested environment-key traversal adds moderate complexity. Clarity of intent: Docstrings, comments, and type hints explain functionality, but single-letter identifiers severely hinder understanding. Documentation references original method and parameter names that no longer match the implementation, and the silent keyword passed to c does not match its signature. Code length: Implementations are reasonably concise, although extensive documentation dominates the file and requires substantial scrolling. Action granularity: Most lines perform one action; the combined read, compile, and exec expression is a notable exception. Reading flow: Consistent formatting and localized error handling support sequential reading, but readers must repeatedly translate opaque identifiers and reconcile documentation with actual signatures.