Sample

pyint-bb7b21d0098b-SRC

Unmodified source class

Lines98

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9190–1; higher is more readable
Mi0.5610–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5810–1; higher is more readable

Views

Source code

from __future__ import annotations import datetime import encodings.idna # noqa: F401 from collections.abc import Callable, Generator, Iterable, Iterator, Mapping from io import UnsupportedOperation from typing import ( TYPE_CHECKING, Any, Final, Literal, cast, overload, ) from urllib3.exceptions import ( DecodeError, LocationParseError, ProtocolError, ReadTimeoutError, SSLError, ) from urllib3.fields import RequestField from urllib3.filepost import encode_multipart_formdata from urllib3.util import parse_url from . import _types as _t from ._internal_utils import to_native_string, unicode_is_ascii from .auth import HTTPBasicAuth from .compat import ( JSONDecodeError, basestring, builtin_str, chardet, cookielib, urlencode, urlsplit, urlunparse, ) from .compat import json as complexjson from .cookies import ( _copy_cookie_jar, cookiejar_from_dict, get_cookie_header, ) from .exceptions import ( ChunkedEncodingError, ConnectionError, ContentDecodingError, HTTPError, InvalidJSONError, InvalidURL, MissingSchema, StreamConsumedError, ) from .exceptions import JSONDecodeError as RequestsJSONDecodeError from .exceptions import SSLError as RequestsSSLError from .hooks import default_hooks from .status_codes import codes from .structures import CaseInsensitiveDict from .utils import ( check_header_validity, get_auth_from_url, guess_filename, guess_json_utf, iter_slices, parse_header_links, requote_uri, stream_decode_response_unicode, super_len, to_key_val_list, ) class RequestHooksMixin: hooks: dict[str, list[_t.HookType]] def register_hook( self, event: str, hook: Iterable[_t.HookType] | _t.HookType ) -> None: """Properly register a hook.""" if event not in self.hooks: raise ValueError(f'Unsupported event specified, with event name "{event}"') if isinstance(hook, Callable): self.hooks[event].append(hook) elif hasattr(hook, "__iter__"): self.hooks[event].extend( h for h in hook if isinstance(h, Callable) ) # defensive runtime filter def deregister_hook(self, event: str, hook: _t.HookType) -> bool: """Deregister a previously registered hook. Returns True if the hook existed, False if not. """ try: self.hooks[event].remove(hook) return True except ValueError: return False

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.2524.999−83.325
Source linesThe number of non-empty source lines.98+39.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.658−6.987

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.94+2.514
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.99−2.469
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.97.875+0.958
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.99+0.599
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.058+0.379
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.929−0.017

Intercept 0.07 + feature contributions = 2.433 (log-odds).
Score = sigmoid(2.433) = 0.919.

Score0.561
Score38
Run 1

The code is generally readable with clear imports and a logical class structure. The RequestHooksMixin has a single responsibility and uses type hints well. However, the large import block is verbose and could be considered unnecessarily long, though this is common in compatibility-focused libraries. The register_hook method has moderate nesting with an if-elif structure and a defensive generator filter that is somewhat dense. The isinstance check for Callable works but is not ideal for checking callables in all Python versions. The deregister_hook's try-except for flow control is acceptable but slightly less clear than using a conditional. Line-level granularity is mostly good, with one action per line in most cases. The reading flow is natural and the intent is clear from method names and docstrings.

Run 2

The code is well-structured and readable. Imports are logically grouped by source (stdlib, third-party, local) with multiple related names per line, which is concise but slightly dense. The class and methods are clear with type hints and docstrings explaining intent. Nesting is minimal: a single conditional in register_hook with flat branches. Action granularity is appropriate—most lines perform one logical operation, though the generator expression in extend() combines iteration and filtering on one line. Reading flow is natural: validation before mutation, clear error handling in deregister_hook with an explicit try/except that avoids deeper nesting. Minor deductions for the dense import blocks and a few lines that could be split for clarity, but overall the code is maintainable and easy to follow.

Run 3

The code is generally readable with clear structure and intent. Imports are organized and type hints improve clarity. However, the massive import block at the top is lengthy and somewhat overwhelming, reducing initial readability. The RequestHooksMixin class has clear methods with docstrings, good action granularity, and minimal nesting. The 'isinstance(hook, Callable)' check works but is semantically unusual since Callable is used as a type, not a class for isinstance checks (though it functions). The 'defensive runtime filter' comment adds helpful context but the generator expression could be slightly more explicit for clarity. Overall, the code is maintainable and logically organized, but the verbose import section and minor implementation quirks prevent it from scoring higher.

Run 1

Code Structure: Imports are grouped by source, and hook management is cleanly encapsulated in a mixin with two focused methods. Nesting: Shallow conditionals and a simple try/except keep complexity low. Clarity of intent: Descriptive method names, type annotations, and docstrings make registration and deregistration clear, though silently filtering non-callable iterable elements is somewhat implicit. Code length: Methods are concise, but the extensive imports, mostly unused in this excerpt, distract from the small implementation. Action granularity: Statements generally perform one action each; the generator expression remains straightforward. Reading flow: Validation precedes registration naturally, and deregistration follows a clear success/failure path. The long import preamble and slightly awkward wrapping of the extend call modestly reduce readability.

Run 2

Code Structure: Imports are grouped logically, and hook operations are cleanly encapsulated in a focused mixin, though the large import section overwhelms the small implementation. Nesting: Methods remain shallow, with straightforward conditionals and exception handling. Clarity of intent: Descriptive method names, type annotations, docstrings, and explicit error messages make behavior clear; the defensive iterable filter adds slight complexity. Code length: Methods are concise, but many imports are unused in the provided excerpt, increasing reading overhead. Action granularity: Statements generally perform one action each; the generator expression combines filtering and iteration compactly without becoming obscure. Reading flow: Registration followed by deregistration is natural, and early validation improves flow. Extra spacing before the class and a more explanatory registration docstring would improve presentation.

Run 3

Code Structure: Imports are grouped coherently, and the mixin separates registration and deregistration into focused methods. Nesting: Control flow is shallow, with straightforward conditionals and a small try/except block. Clarity of intent: Descriptive method names, type annotations, and docstrings make hook management clear; the defensive filter explains why non-callable iterable elements are ignored. Code length: Methods are concise, but the extensive import section is disproportionate to this excerpt and includes many names not used here. Action granularity: Each statement generally performs one action, while the generator expression compactly expresses filtering. Reading flow: Validation precedes mutation naturally, and deregistration follows a simple success/failure pattern. Minor drawbacks include the abbreviated '_t' alias, a generic registration docstring that omits filtering behavior, and substantial import overhead before the relevant logic.