Sample

pyint-b0d43fbb9c3a-I01

Remove comments and docstrings

Matched original source

Lines202

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1250–1; higher is more readable
Mi0.7290–1; higher is more readable
LLOC93Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.2670–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 RequestEncodingMixin: url: str | None @property def path_url(self) -> str: url: list[str] = [] p = urlsplit(cast(str, self.url)) path = p.path if not path: path = "/" url.append(path) query = p.query if query: url.append("?") url.append(query) return "".join(url) @overload @staticmethod def _encode_params(data: str) -> str: ... @overload @staticmethod def _encode_params(data: bytes) -> bytes: ... @overload @staticmethod def _encode_params( data: _t.SupportsRead[str | bytes], ) -> _t.SupportsRead[str | bytes]: ... @overload @staticmethod def _encode_params(data: _t.KVDataType) -> str: ... @staticmethod def _encode_params( data: _t.EncodableDataType, ) -> str | bytes | _t.SupportsRead[str | bytes]: if isinstance(data, (str, bytes)): return data elif _t.has_read(data): return data elif hasattr(data, "__iter__"): result: list[tuple[bytes, bytes]] = [] for k, vs in to_key_val_list(data): if isinstance(vs, basestring) or not hasattr(vs, "__iter__"): vs = [vs] for v in vs: if v is not None: result.append( ( k.encode("utf-8") if isinstance(k, str) else k, v.encode("utf-8") if isinstance(v, str) else v, ) ) return urlencode(result, doseq=True) else: return data @staticmethod def _encode_files( files: _t.FilesType, data: _t.RawDataType | None ) -> tuple[bytes, str]: if not files: raise ValueError("Files must be provided.") elif isinstance(data, basestring): raise ValueError("Data must not be a string.") new_fields: list[RequestField | tuple[str, bytes]] = [] fields = to_key_val_list(data or {}) files = to_key_val_list(files or {}) for field, val in fields: if isinstance(val, basestring) or not hasattr(val, "__iter__"): val = [val] for v in val: if v is not None: if not isinstance(v, bytes): v = str(v) new_fields.append( ( field.decode("utf-8") if isinstance(field, bytes) else field, v.encode("utf-8") if isinstance(v, str) else v, ) ) for k, v in files: ft = None fh = None if isinstance(v, (tuple, list)): if len(v) == 2: fn, fp = v elif len(v) == 3: fn, fp, ft = v else: fn, fp, ft, fh = v else: fn = guess_filename(v) or k fp = v if isinstance(fp, (str, bytes, bytearray)): fdata = fp elif _t.has_read(fp): fdata = fp.read() elif fp is None: continue else: fdata = fp rf = RequestField(name=k, data=fdata, filename=fn, headers=fh) rf.make_multipart(content_type=ft) new_fields.append(rf) body, content_type = encode_multipart_formdata(new_fields) return body, content_type

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.6623.5−218.575
Source linesThe number of non-empty source lines.202+80.8
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.202−6.303

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.202+6.25
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.203−6.151
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.202−4.214
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.201.925+2.413
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
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.946+0.321
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.079+0.171

Intercept 0.07 + feature contributions = -1.945 (log-odds).
Score = sigmoid(-1.945) = 0.125.

Score0.729
Score93
Run 1

The code demonstrates moderate readability. The structure is logical with clear separation of imports, class definition, and methods, but it suffers from several issues. The nesting in `_encode_params` and `_encode_files` creates complexity with multiple levels of conditionals and loops. Some methods have unused or unnecessary blank lines after docstrings. The action granularity is mixed - some lines pack multiple operations while others are appropriately separated. The intent is generally clear due to naming conventions, but the heavy use of type hints and overloads adds visual noise. The `_encode_files` method is particularly long and complex, handling multiple file format variations in a single method. The imports section is extensive and well-organized, but the overall code density is high. The reading flow is interrupted by the complexity of type annotations and the unpacking logic in file handling. While the code follows Python conventions, the complexity of the logic makes it harder to follow than necessary.

Run 2

The code is moderately readable but has several issues. The imports are extensive and well-organized, though poorly formatted (missing commas, incorrect indentation). The class structure is logical, but methods are overly long - particularly _encode_files which mixes multiple responsibilities and levels of abstraction. Nesting is acceptable in most places but becomes deep in the file-processing loop with nested conditionals and tuple unpacking. Variable names are mostly clear (path, query, fields, files) but some are cryptic (_t, fh, ft, rf). Action granularity is inconsistent - some lines are concise while others pack multiple operations. The blank lines and empty function bodies (containing only whitespace) hint at missing docstrings. Type hints are present but complex overloads add noise. The _encode_params method has redundant branching with elif chains that could be simplified. Reading flow is disrupted by the long _encode_files method and inconsistent formatting throughout.

Run 3

The code is generally well-structured with clear imports, organized methods, and type hints that enhance clarity. The class methods follow logical flow and keep actions reasonably granular. However, readability is impacted by a few deeply nested loops and conditional branches, particularly in _encode_params and _encode_files. Some blocks contain multiple assertions or variable assignments per line, which slightly reduces scanability. The use of overloads and static methods is clear but adds complexity. While the intent is mostly evident, certain ambiguous patterns (e.g., mixed tuple/list handling for file descriptors) require close reading. Overall, the code is above average but not exceptionally readable due to moderate nesting and occasional density.

Run 1

Code Structure: Imports and related encoding methods are logically organized within a mixin, although the extensive import block distracts from the implementation. Nesting: Most control flow is manageable, but parameter and multipart encoding contain nested loops and conditionals that require careful tracking. Clarity of intent: Method names, type annotations, and explicit validation communicate purpose well; abbreviated variables such as k, vs, fn, fp, ft, and fh and absent explanatory documentation obscure details. Code length: Implementations are reasonably concise, but overload declarations and excess blank lines interrupt compactness. Action granularity: Statements generally perform one action each, with tuple unpacking and inline conditional conversions adding some density. Reading flow: Methods progress naturally from validation through normalization to encoding, though repeated branching, reused variables, and multiline expressions make some sections slower to follow.

Run 2

Code Structure: Imports are grouped, and a cohesive mixin separates URL construction, parameter encoding, and multipart encoding into focused methods. Nesting: Parameter and field processing contain several nested loops and conditionals, making some paths harder to follow. Clarity of intent: Descriptive method names and type annotations communicate purpose, but abbreviated variables such as k, vs, ft, fh, and fp, plus missing explanatory comments, obscure multipart details. Code length: Mostly justified by supported input formats, although overload declarations and verbose conversion expressions add reading overhead. Action granularity: Generally one operation per line, with clear intermediate assignments; inline conditional conversions are somewhat dense. Reading flow: Methods follow a logical validation-to-transformation-to-return progression, but excessive blank lines, trailing whitespace, and repeated branching interrupt the flow.

Run 3

Code Structure: Imports are grouped logically, and encoding responsibilities are separated into focused methods within a mixin. Nesting: Parameter and field encoding contain several nested loops and conditionals, making those sections harder to follow. Clarity of intent: Method names and type annotations communicate purpose, but abbreviated variables such as k, vs, fn, fp, ft, and fh obscure details; documentation would help explain supported input forms. Code length: Generally proportionate to the functionality, although overload declarations, extensive imports, and unnecessary blank lines increase scanning effort. Action granularity: Statements generally perform one action each, with no compressed multi-statement lines; inline conditional expressions add some complexity. Reading flow: Validation, normalization, encoding, and return steps follow a natural sequence, but inconsistent whitespace and dense tuple construction interrupt the flow.