Sample

pyint-0cf995cfffd5-I01

Remove comments and docstrings

Matched original source

Lines211

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.9270–1; higher is more readable
Mi0.5310–1; higher is more readable
LLOC121Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.5520–1; higher is more readable

Views

Source code

from __future__ import annotations import calendar import copy import time from collections.abc import Iterator, MutableMapping from http.cookiejar import Cookie, CookieJar, CookiePolicy from typing import TYPE_CHECKING, Any, TypeVar, overload from ._internal_utils import to_native_string from ._types import is_prepared as _is_prepared from .compat import Morsel, cookielib, urlparse, urlunparse import threading class RequestsCookieJar(CookieJar, MutableMapping[str, str | None]): _policy: CookiePolicy def get( self, name: str, default: str | None = None, domain: str | None = None, path: str | None = None, ) -> str | None: try: return self._find_no_duplicates(name, domain, path) except KeyError: return default def set( self, name: str, value: str | Morsel[dict[str, str]] | None, **kwargs: Any ) -> Cookie | None: if value is None: remove_cookie_by_name( self, name, domain=kwargs.get("domain"), path=kwargs.get("path") ) return if isinstance(value, Morsel): c = morsel_to_cookie(value) else: c = create_cookie(name, value, **kwargs) self.set_cookie(c) return c def iterkeys(self) -> Iterator[str]: for cookie in iter(self): yield cookie.name def keys(self) -> list[str]: return list(self.iterkeys()) def itervalues(self) -> Iterator[str | None]: for cookie in iter(self): yield cookie.value def values(self) -> list[str | None]: return list(self.itervalues()) def iteritems(self) -> Iterator[tuple[str, str | None]]: for cookie in iter(self): yield cookie.name, cookie.value def items(self) -> list[tuple[str, str | None]]: return list(self.iteritems()) def list_domains(self) -> list[str]: domains: list[str] = [] for cookie in iter(self): if cookie.domain not in domains: domains.append(cookie.domain) return domains def list_paths(self) -> list[str]: paths: list[str] = [] for cookie in iter(self): if cookie.path not in paths: paths.append(cookie.path) return paths def multiple_domains(self) -> bool: domains: list[str] = [] for cookie in iter(self): if cookie.domain is not None and cookie.domain in domains: return True domains.append(cookie.domain) return False def get_dict( self, domain: str | None = None, path: str | None = None ) -> dict[str, str | None]: dictionary: dict[str, str | None] = {} for cookie in iter(self): if (domain is None or cookie.domain == domain) and ( path is None or cookie.path == path ): dictionary[cookie.name] = cookie.value return dictionary def __iter__(self) -> Iterator[Cookie]: return super().__iter__() def __contains__(self, name: object) -> bool: try: return super().__contains__(name) except CookieConflictError: return True def __getitem__(self, name: str) -> str | None: return self._find_no_duplicates(name) def __setitem__( self, name: str, value: str | Morsel[dict[str, str]] | None ) -> None: self.set(name, value) def __delitem__(self, name: str) -> None: remove_cookie_by_name(self, name) def set_cookie(self, cookie: Cookie, *args: Any, **kwargs: Any) -> None: if ( (value := cookie.value) is not None and value.startswith('"') and value.endswith('"') ): cookie.value = value.replace('\\"', "") return super().set_cookie(cookie, *args, **kwargs) def update( self, other: CookieJar | SupportsKeysAndGetItem[str, str] ) -> None: if isinstance(other, cookielib.CookieJar): for cookie in other: self.set_cookie(copy.copy(cookie)) else: super().update(other) def _find( self, name: str, domain: str | None = None, path: str | None = None ) -> str | None: for cookie in iter(self): if cookie.name == name: if domain is None or cookie.domain == domain: if path is None or cookie.path == path: return cookie.value raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}") def _find_no_duplicates( self, name: str, domain: str | None = None, path: str | None = None ) -> str: toReturn = None for cookie in iter(self): if cookie.name == name: if domain is None or cookie.domain == domain: if path is None or cookie.path == path: if toReturn is not None: raise CookieConflictError( f"There are multiple cookies with name, {name!r}" ) toReturn = cookie.value if toReturn is not None: return toReturn raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}") def __getstate__(self) -> dict[str, Any]: state = self.__dict__.copy() state.pop("_cookies_lock") return state def __setstate__(self, state: dict[str, Any]) -> None: self.__dict__.update(state) if "_cookies_lock" not in self.__dict__: self._cookies_lock = threading.RLock() def copy(self) -> RequestsCookieJar: new_cj = RequestsCookieJar() new_cj.set_policy(self.get_policy()) new_cj.update(self) return new_cj def get_policy(self) -> CookiePolicy: return self._policy

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.8315.156−274.4
Source linesThe number of non-empty source lines.211+84.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.206−6.309

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.211+6.561
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.210−6.399
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.210.795+2.537
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
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.81.958+0.194
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.098−0.011

Intercept 0.07 + feature contributions = 2.545 (log-odds).
Score = sigmoid(2.545) = 0.927.

Score0.531
Score121
Run 1

The code is generally readable but has several issues. Structure is logical with clear method grouping, but imports are disorganized (threading at bottom). Nesting is problematic in _find and _find_no_duplicates with three-level nested conditionals. Intent is mostly clear but some methods have empty docstrings instead of meaningful documentation. Code length is reasonable with concise methods. Action granularity follows one-action-per-line well. Reading flow is natural, following Python conventions. The main issues are: unnecessary empty docstrings, inconsistent type hints, the walrus operator in set_cookie makes intent less clear, and multiple_domains has a logic issue (checks domain in list before appending). The nested conditionals in _find methods could be flattened using early returns or continue statements. Some methods like _find_no_duplicates could be more concise with better structure.

Run 2

The code is generally well-structured with clear method organization and type hints. Nested conditions in `_find_no_duplicates` and `_find` could be flattened using early continues or combined conditions. The use of walrus operator in `set_cookie` improves conciseness but may slightly reduce readability. Magic methods are appropriately grouped together. Some methods like `multiple_domains` have redundant type annotations and could use set() for clarity. Empty comment blocks (docstring placeholders with only whitespace) are minor noise. Overall, the code is readable with clear intent and good naming, but minor nesting depth and redundant annotations prevent a higher score.

Run 3

The code is generally clear and well-structured, but has a few readability issues. Positives: logical class organization with related methods grouped, flat nesting in most methods, clear intent with descriptive names, one action per line mostly, and natural reading flow. The methods are concise, and type hints improve clarity. Negatives: excessive blank lines (e.g., between method signature and body, multiple consecutive spaces after colons), inconsistent spacing in type hints (e.g., 'str | None' vs 'CookieJar | SupportsKeysAndGetItem'), and a few slightly dense lines such as the conditional stription in set_cookie. The _find and _find_no_duplicates methods have triple nesting, which slightly reduces readability. Some methods like list_domains and list_paths could be more concise with set comprehension. Overall, the code is above average in readability but would benefit from consistent formatting and minor refactoring.

Run 1

Code Structure: Logically organized into focused cookie-access, mapping, lookup, and serialization methods, although grouping could be clearer. Nesting: Most methods are shallow, but _find and _find_no_duplicates contain unnecessarily deep conditional chains. Clarity of intent: Descriptive method names and type annotations communicate purpose well; absent documentation, abbreviated variables such as c and new_cj, inconsistent toReturn naming, and surprising multiple_domains behavior weaken clarity. Code length: Methods are generally concise, but repeated iteration patterns, redundant wrappers, and excessive blank lines add noise. Action granularity: Statements generally perform one action per line; the assignment expression in set_cookie slightly increases density. Reading flow: Conventional method implementations are easy to follow, but inconsistent whitespace, scattered import ordering, and nested lookup logic interrupt the flow.

Run 2

Code Structure: The class is logically organized into mapping operations, cookie lookup, serialization, and copying, with small, focused methods. Nesting: Most methods are shallow, but _find and _find_no_duplicates use unnecessarily deep conditional chains. Clarity of intent: Descriptive method names and type annotations help, while missing docstrings, abbreviated variables such as c and new_cj, and inconsistent toReturn naming reduce clarity. The multiple_domains implementation also appears at odds with its name, complicating interpretation. Code length: Individual methods are concise, although repetitive lookup logic and excessive blank whitespace add avoidable bulk. Action granularity: Statements generally perform one action per line; the assignment expression in set_cookie slightly increases cognitive load. Reading flow: Method grouping is natural, but inconsistent whitespace, threading imported after local imports, and externally defined helpers and types make the snippet less self-contained.

Run 3

Code Structure: Methods are logically grouped within a focused cookie-jar class, though import ordering and excessive blank whitespace reduce polish. Nesting: Most methods are shallow, but _find and _find_no_duplicates contain three to four nested conditionals that could be flattened. Clarity of intent: Descriptive method names and type annotations communicate purpose well; abbreviated variables, inconsistent toReturn naming, and undocumented duplicate-handling and serialization behavior weaken clarity. Code length: Individual methods are concise, but repeated filtering logic and iterator/list wrappers add verbosity. Action granularity: Statements generally perform one action per line; the assignment expression in set_cookie slightly increases cognitive load. Reading flow: Public operations precede lookup and serialization helpers in a mostly natural sequence, but missing definitions for referenced helpers/types and unused imports distract when reading this snippet independently.