Sample

pyint-52a272e84757-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines76

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8080–1; higher is more readable
Mi0.5150–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro10.670–20; mean of three runs
GPT-6.1 Sol13.330–20; mean of three runs
BTTF0.5390–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.76+30.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.639−6.958

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.72+1.753
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.77−1.69
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.113.974−1.162
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.113.987+1.035
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.75.87+0.651
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.057+0.383

Intercept 0.07 + feature contributions = 1.438 (log-odds).
Score = sigmoid(1.438) = 0.808.

Score0.515
Score38
Run 1

The code has clear structure with logical imports and well-defined methods, but readability is hampered by inconsistent formatting and alignment. The import section has erratic spacing and alignment, making it visually noisy. The class methods are flat and have clear intent with concise docstrings, but the register_hook method contains a moderately nested conditional and a defensive runtime filter that adds complexity. Action granularity varies, with some lines containing multiple operations. The type annotations are thorough and helpful, improving clarity. Overall, the code is functional but would benefit from consistent formatting and minor decomposition to enhance readability.

Run 2

The code exhibits readability issues primarily due to inconsistent formatting, especially in imports where alignment is erratic and some imports are excessively long or fragmented across lines. The class methods are logically structured but lack separation—no blank lines between methods, making the class feel dense. Nesting is minimal, which is positive, and action granularity is generally reasonable, though some conditionals could be clearer. The intent of each method is reasonably clear via docstrings, but the overall reading flow is disrupted by inconsistent spacing, unusual indentation in function signatures, and a few very long lines. Variable naming is acceptable. The code is understandable but requires effort due to stylistic inconsistency and visual noise, placing it in the mid-to-low readability range.

Run 3

The code suffers from severe import statement misalignment and inconsistent spacing, making it visually chaotic and difficult to scan. Multiple imports are bundled on single lines (e.g., 'Any, Final'), while others are awkwardly split, hurting readability. The class logic itself is relatively clear, but the method signatures have odd spacing before closing parentheses, and type hints are verbose without clear separation. Nesting is minimal, which is good, but the overall structure is undermined by formatting inconsistencies. Action granularity is mostly one-per-line inside methods, and intent is somewhat clear, but the import section dominates the file and obscures purpose. The code appears to be auto-formatted poorly or hand-edited inconsistently. Overall, it is readable with effort but far from clean or natural to follow.

Run 1

Code Structure: Imports are broadly grouped and hook operations are logically contained in a mixin, but inconsistent formatting and limited spacing between methods weaken organization. Nesting: Shallow conditionals and a simple try/except keep control flow easy to follow. Clarity of intent: Descriptive method names, type annotations, and docstrings clearly explain registration and deregistration; the callable filter is understandable. Code length: Methods are concise, although the extensive import section dominates this excerpt and introduces visual overhead. Action granularity: Executable statements generally perform one action per line, but several crowded import lines hinder scanning. Reading flow: Method logic progresses naturally from validation to mutation or success reporting, while irregular whitespace, awkward line wrapping, and missing blank lines interrupt readability.

Run 2

Code Structure: Imports precede a cohesive mixin, and hook registration and removal are cleanly separated, but inconsistent import grouping and missing blank lines reduce organization. Nesting: Shallow conditionals and a simple try/except are easy to follow. Clarity of intent: Descriptive method names, type annotations, and docstrings clearly communicate behavior; the defensive callable filter is explained. Code length: Methods are concise, although the large import block overwhelms this small excerpt. Action granularity: Executable statements generally perform one action per line, but multiple imported names crowded onto irregularly spaced lines hinder scanning. Reading flow: Control flow is natural and straightforward, while inconsistent spacing, awkward line wrapping, and minimal separation between methods interrupt readability.

Run 3

Code Structure: Imports precede a logically organized mixin, but the extensive import section overwhelms the small implementation and lacks consistent formatting. Nesting: Methods remain shallow, with simple conditionals, a generator expression, and straightforward exception handling. Clarity of intent: Descriptive method names, type annotations, and docstrings clearly explain hook registration and removal. Code length: The methods are concise, although the import-heavy excerpt adds substantial reading overhead. Action granularity: Statements generally perform one action per line; crowded import lines reduce visual clarity without combining executable actions. Reading flow: Method logic reads naturally, but irregular spacing, inconsistent import wrapping, and missing blank lines between methods disrupt scanning.