Sample

pyint-07a593de36a9-I01

Remove comments and docstrings

Matched original source

Lines96

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7490–1; higher is more readable
Mi0.7290–1; higher is more readable
LLOC36Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol15.670–20; mean of three runs
BTTF0.5740–1; higher is more readable

Views

Source code

from __future__ import annotations import datetime import encodings.idna 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: 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) ) def deregister_hook(self, event: str, hook: _t.HookType) -> bool: 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.2503.008−82.599
Source linesThe number of non-empty source lines.96+38.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.638−6.957

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.96+2.583
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.97−2.398
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.95.909+0.931
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.063+0.329
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.918−0.016

Intercept 0.07 + feature contributions = 1.092 (log-odds).
Score = sigmoid(1.092) = 0.749.

Score0.729
Score36
Run 1

The code is highly readable due to its clear structure and logical organization. Imports are grouped by source (standard library, third-party, local), making dependencies obvious. The class has a single responsibility with well-named, focused methods. Nesting is minimal—only one conditional level and a try/except block, both flat and easy to follow. Naming conventions clearly express intent (e.g., `register_hook`, `deregister_hook`, `if isinstance(hook, Callable)`). The use of type hints, modern union syntax, and `Final`/`overload` imports signals maintainability. Minor deductions are for some blank lines and the slightly unusual placement of the `isinstance` check before the iterable check, but overall the code flows naturally and requires little effort to understand.

Run 2

The code is well-structured and readable overall. It uses clear type hints, modern Python features (e.g., `from __future__ import annotations`, union syntax), and logical grouping of imports. Functions are short, with single-purpose actions and flat nesting. Intent is explicit in method names and error messages. The `register_hook` and `deregister_hook` methods are concise and avoid deep nesting. However, some minor issues slightly reduce readability: the large number of imports (though organized) adds visual noise, and there are a couple of blank-line inconsistencies and trailing spaces. The `isinstance(hook, Callable)` check could be more clearly expressed. Overall, the code demonstrates good action granularity and natural reading flow, with only minor stylistic blemishes preventing a higher score.

Run 3

The code is moderately readable but has several issues. The imports section is excessively long and includes an unused 'encodings.idna' import, which creates noise. The class structure is logical, but the hook registration method has unnecessary blank lines and a trailing line with whitespace. The isinstance check for Callable is incorrect - Callable is not a class that can be used with isinstance. The error message uses f-string inconsistently with the rest of the codebase style. The deregister_hook method has a trailing underscore in its name which is unconventional. The code lacks docstrings for the class and methods. Overall, the logic is straightforward but the implementation details and minor style inconsistencies reduce readability.

Run 1

Code Structure: Imports are grouped and hook operations are cleanly separated into two methods, although many imports are unrelated to the shown class. Nesting: Shallow conditionals and a straightforward try/except keep complexity low. Clarity of intent: Descriptive method names and type annotations make registration and deregistration clear; silently filtering non-callable iterable elements is less obvious. Code length: The methods are concise, but the lengthy import section and excess blank lines add visual overhead. Action granularity: Statements generally perform one action each; the generator expression remains compact and understandable. Reading flow: Validation precedes registration naturally, and deregistration follows a simple success/failure pattern. Inconsistent whitespace and the disproportionate import section slightly disrupt the otherwise clear flow.

Run 2

Code Structure: Imports are grouped and hook operations are separated into focused methods, although the extensive import block overwhelms the small implementation. Nesting: Shallow conditionals and a simple try/except keep complexity low. Clarity of intent: Descriptive class and method names, type annotations, and an explicit error message make registration and deregistration easy to understand; absent documentation leaves some behavior implicit. Code length: Methods are concise, but numerous imports unused in the shown snippet and excessive blank lines add clutter. Action granularity: Each statement performs a distinct action; the generator expression compactly expresses filtering. Reading flow: Method logic follows a natural validation-then-update sequence, but inconsistent whitespace and disproportionate import overhead interrupt scanning.

Run 3

Code Structure: Imports are grouped and hook operations are organized into a focused mixin, though the extensive import block overwhelms the small implementation. Nesting: Shallow conditionals and a simple try/except keep complexity low. Clarity of intent: Descriptive class and method names, type annotations, and an explicit error message make behavior clear; the iterable filtering is slightly less immediately obvious. Code length: Methods are concise, but many imports are unused in this snippet, and extra blank lines add clutter. Action granularity: Statements generally perform one action per line; the generator expression compactly combines filtering and iteration without becoming difficult to follow. Reading flow: Registration followed by deregistration is logical, but inconsistent whitespace and unnecessary line wrapping interrupt an otherwise straightforward presentation.