Sample

pyint-7120cb631091-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines98

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9230–1; higher is more readable
Mi0.5610–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro14.330–20; mean of three runs
GPT-6.1 Sol14.670–20; mean of three runs
BTTF0.5850–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( self, eve: str, hoo: Iterable[_t.HookType] | _t.HookType ) -> None: """Properly register a hook.""" if eve not in self.hooks: raise ValueError(f'Unsupported event specified, with event name "{eve}"') if isinstance(hoo, Callable): self.hooks[eve].append(hoo) elif hasattr(hoo, "__iter__"): self.hooks[eve].extend( h2 for h2 in hoo if isinstance(h2, Callable) ) # defensive runtime filter def deregister(self, eve2: str, hoo2: _t.HookType) -> bool: """Deregister a previously registered hook. Returns True if the hook existed, False if not. """ try: self.hooks[eve2].remove(hoo2) 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.2532.846−83.584
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.666−6.998

Intercept 8.87 + feature contributions = -42.512 (log-odds).
Score = sigmoid(-42.512) = 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.826+0.958
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.84.98+0.567
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.374
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.84.929+0.068

Intercept 0.07 + feature contributions = 2.479 (log-odds).
Score = sigmoid(2.479) = 0.923.

Score0.561
Score38
Run 1

The code is generally structured well with clear sections for imports and class definition. The import statements are organized logically, grouping standard library, third-party, and local imports. Nesting is minimal, with only one level of conditionals in methods. However, clarity of intent is compromised by cryptic parameter names like 'eve', 'hoo', 'eve2', and 'hoo2' instead of more descriptive names like 'event' and 'hook'. The action granularity is acceptable, though the generator expression with a defensive runtime filter could be more readable if expanded. Reading flow is mostly natural but interrupted by the unconventional parameter naming. The type hints are thorough, which aids readability. Overall, the code is relatively readable but suffers from poor variable naming choices that obscure intent without documentation.

Run 2

The code is generally readable with clear imports, type hints, and docstrings. The RequestHooksMixin class is logically structured with two methods that each perform focused actions. Error handling is straightforward and nesting is minimal. However, readability is slightly reduced by unclear parameter names like 'eve', 'hoo', 'eve2', and 'hoo2', which obscure intent despite the docstrings. The defensive generator expression in register() is somewhat dense and could be split for clarity. Import organization is good but lengthy. Overall the code is maintainable but would benefit from more descriptive naming.

Run 3

The code has a clear structure with organized imports and a cohesive class definition, but readability suffers in several areas. The nesting is mostly flat, which is positive, but the logic for registering hooks is slightly tangled with mixed type checking and a defensive generator expression. Intent is reasonably clear due to docstrings and type hints, but variable names like 'eve', 'hoo', 'eve2', and 'hoo2' are ambiguous and hurt clarity. Code length is moderate, though the extensive import block feels verbose. Action granularity is mostly one action per line, except for the generator expression which packs multiple steps into one line. Reading flow is generally natural, but the abrupt variable naming and inconsistent event/hook parameter naming break mental flow. Overall, the code is functional but not highly readable without renaming variables and simplifying the registration logic.

Run 1

Code Structure: Imports are grouped logically, and hook registration and deregistration are separated into focused methods, though most imports are unused in this excerpt. Nesting: Shallow conditionals and a simple try/except keep complexity low. Clarity of intent: Method names, type annotations, and docstrings communicate purpose, but abbreviated parameters such as eve, hoo, eve2, and hoo2 obscure meaning and lack consistency. Code length: The methods are concise, but the extensive import section overwhelms the small implementation shown. Action granularity: Statements generally perform one action each; the generator expression compactly combines filtering and iteration without becoming difficult to follow. Reading flow: The class follows a natural register/deregister sequence, but the long import preamble and awkward line wrapping interrupt readability.

Run 2

Code Structure: Imports are grouped logically, and hook operations are cleanly separated into two methods, though the extensive imports overwhelm this small excerpt. Nesting: Shallow conditionals and a straightforward try/except keep complexity low. Clarity of intent: Class and method names, type annotations, and docstrings communicate purpose, but abbreviated and inconsistent parameter names (eve, hoo, eve2, hoo2, h2) obscure meaning. Code length: Methods are concise, while the large import block adds substantial reading overhead and includes many names unused in the excerpt. Action granularity: Statements generally perform one action per line; the generator expression combines filtering and iteration but remains manageable. Reading flow: Registration followed by deregistration is natural, although awkward signature wrapping, inconsistent naming, and limited spacing before the class slightly disrupt scanning.

Run 3

1. Code Structure: Imports are grouped and hook operations are encapsulated in a focused mixin, but the extensive imports obscure the small implementation. 2. Nesting: Shallow conditionals and a simple try/except keep control flow easy to follow. 3. Clarity of intent: Method names, docstrings, and type annotations explain the purpose, but abbreviated parameters (eve, hoo, eve2, hoo2) and h2 reduce clarity. 4. Code length: Methods are concise, though the import section is disproportionately long for the shown code. 5. Action granularity: Statements generally perform one action per line; the generator expression combines filtering and iteration compactly without excessive complexity. 6. Reading flow: Registration followed by deregistration is natural, but inconsistent parameter naming and awkward line wrapping interrupt otherwise straightforward reading.