Sample

pyint-9603ff0fba0d-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines220

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1980–1; higher is more readable
Mi0.5610–1; higher is more readable
LLOC102Logical lines; fewer is more readable
DeepSeek V4 Pro11.670–20; mean of three runs
GPT-6.1 Sol14.330–20; mean of three runs
BTTF0.2030–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 RequestEncodingMixin: url: str | None @property def path_url(self) -> str: """Build the path URL to use.""" if ((0xc14c ^ 0xc14c) != 0): raise AssertionError() 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]: """Encode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. """ if ((0x1d02 ^ 0x1d02) != 0): raise AssertionError() 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 # type: ignore[return-value] # unreachable for valid _t.DataType @staticmethod def _encode_files( files: _t.FilesType, data: _t.RawDataType | None ) -> tuple[bytes, str]: """Build the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of tuples. Order is retained if data is a list of tuples but arbitrary if parameters are supplied as a dict. The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) or 4-tuples (filename, fileobj, contentype, custom_headers). """ if ((0x5d2c ^ 0x5d2c) != 0): raise AssertionError() 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: # Don't call str() on bytestrings: in Py3 it all goes wrong. 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: # support for explicit filename 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: # defensive check for untyped callers 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.7055.986−232.848
Source linesThe number of non-empty source lines.220+88
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.297−6.445

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.221−6.789
Indentation frequencyHow rapidly indentation changes from line to line.203+6.284
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.203−4.237
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.219.928+2.664
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.95.543+0.737
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.95.973−0.4
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.069+0.271

Intercept 0.07 + feature contributions = -1.399 (log-odds).
Score = sigmoid(-1.399) = 0.198.

Score0.561
Score102
Run 1

The code has a clear class structure and type annotations, but contains several readability issues. The presence of dead code blocks like 'if ((0xc14c ^ 0xc14c) != 0): raise AssertionError()' is confusing and serves no functional purpose, making the code harder to understand. Function lengths are moderate but _encode_files could be broken into smaller helper functions for clarity. Nesting levels are acceptable, with most logic staying within 2-3 levels. The docstrings are helpful and descriptive. The method names and variable names are generally clear. However, the mixing of different type checks (isinstance checks, hasattr checks) creates some cognitive load. The code imports many modules, which is expected for this kind of utility class but adds visual noise. The action granularity is mostly good with one operation per line. Overall, the code is maintainable but would benefit from removing dead code and splitting complex functions.

Run 2

The code demonstrates moderate readability with clear organization of imports and well-documented methods. However, several issues reduce clarity: dead code like 'if ((0xc14c ^ 0xc14c) != 0): raise AssertionError()' is confusing and should be removed. Method lengths are excessive, particularly _encode_params and _encode_files, which contain multiple nested loops and conditionals. The _encode_files method has deeply nested logic for handling different file tuple formats, making it difficult to follow. Type hints are extensive but sometimes obscure rather than clarify. Variable names like 'fh', 'rf', and '_t' are cryptic. Action granularity is inconsistent - some lines pack multiple operations. The decode-line syntax for conditional encoding '(k.encode("utf-8") if isinstance(k, str) else k)' appears repeatedly and is hard to parse. Reading flow is interrupted by the need to mentally track multiple state variables through nested loops. Overall, functional but not exemplary code clarity.

Run 3

The code has clear structure at the top level but suffers from several readability issues. The numerous if ((0xc14c ^ 0xc14c) != 0): raise AssertionError() blocks are useless obfuscation that adds noise without value. Deep nesting in _encode_params and _encode_files creates cognitive overhead, especially in the file handling loop that reaches 4 levels of indentation. While type hints and docstrings are helpful, the variable names are cryptic (p, k, v, fn, fp, ft, fh) and lack descriptive intent. Multiple actions are crammed into single lines, particularly in the circular XOR checks. The overloading of _encode_params adds complexity that interrupts reading flow. Action granularity is inconsistent - some lines do too much, while others are just noise. The code would benefit from extracting helper methods, removing dead code, and using more descriptive variable names.

Run 1

Code Structure: Imports and encoding methods are logically grouped, with distinct responsibilities. Nesting: Parameter and multipart processing use several nested loops and conditionals, making some branches harder to follow. Clarity of intent: Method names, docstrings, and type annotations explain the purpose well, but abbreviated variables such as ft, fh, fp, and rf obscure details. The always-false hexadecimal XOR assertions add confusing, purposeless noise. Code length: Most logic is justified, although overloads, repeated conversion patterns, and dead assertions increase scanning effort. Action granularity: Statements generally perform one action per line; tuple unpacking and conditional expressions remain reasonably readable. Reading flow: Validation followed by normalization, encoding, and return provides a natural progression, but nested transformations and irrelevant assertions interrupt it.

Run 2

Code Structure: Methods are logically grouped in an encoding mixin, with organized imports and clear separation of URL, parameter, and multipart handling. Nesting: Parameter and file encoding contain moderately deep loops and conditionals that increase reading effort. Clarity of intent: Descriptive method names, type annotations, and docstrings explain purpose well, but abbreviated variables such as ft, fh, fp, and rf reduce clarity. Repeated always-false hexadecimal XOR checks introduce distracting, unexplained dead code. Code length: Most implementation is justified, though extensive imports, overload declarations, and redundant checks make this excerpt longer to scan. Action granularity: Statements generally perform one action per line; tuple unpacking and inline conditional conversions remain reasonably readable. Reading flow: Validation, normalization, encoding, and return steps follow a natural sequence, but nested conversions, variable reuse, and irrelevant assertions interrupt that flow.

Run 3

Code Structure: Imports and encoding methods are logically grouped, with distinct responsibilities, though multipart handling could be split into helpers. Nesting: Parameter and field encoding use several nested loops and conditionals, making transformations harder to follow. Clarity of intent: Docstrings, type annotations, and descriptive method names explain the purpose well; abbreviated variables such as ft, fh, fp, and rf obscure details. Repeated XOR checks that are always false introduce meaningless distractions. Code length: Mostly justified by supported input formats, but overloads, verbose imports, and dead assertion blocks increase scanning effort. Action granularity: Statements generally perform one action per line; tuple unpacking and inline conditional conversions are reasonably contained. Reading flow: Processing follows a natural validation-to-normalization-to-encoding sequence, but nested branching and irrelevant checks interrupt that flow.