Sample

pyint-d1680f2a3435-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines298

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0220–1; higher is more readable
Mi0.6040–1; higher is more readable
LLOC145Logical lines; fewer is more readable
DeepSeek V4 Pro5.670–20; mean of three runs
GPT-6.1 Sol110–20; mean of three runs
BTTF0.350–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]): # type: ignore[misc] """Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of ``CookieJar``, e.g. ``LWPCookieJar`` and ``FileCookieJar``. Unlike a regular CookieJar, this class is pickleable. .. warning:: dictionary operations that are normally O(1) may be O(n). """ _policy: CookiePolicy def get2( # type: ignore[override] self, nam: str, def2: str | None = None, dom: str | None = None, pat: str | None = None, ) -> str | None: """Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. .. warning:: operation is O(n), not O(1). """ try: return self.find(nam, dom, pat) except KeyError: return def2 def set2( self, nam2: str, val2: str | Morsel[dict[str, str]] | None, **kwa: Any ) -> Cookie | None: """Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. """ # support client code that unsets cookies by assignment of a None value: if val2 is None: remove_cookie_by_name( self, nam2, domain=kwa.get("domain"), path=kwa.get("path") ) return if isinstance(val2, Morsel): c2 = morsel_to_cookie(val2) else: c2 = create_cookie(nam2, val2, **kwa) self.set3(c2) return c2 def ite(self) -> Iterator[str]: """Dict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems(). """ for coo in iter(self): yield coo.name def key(self) -> list[str]: # type: ignore[override] """Dict-like keys() that returns a list of names of cookies from the jar. .. seealso:: values() and items(). """ return list(self.ite()) def ite2(self) -> Iterator[str | None]: """Dict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems(). """ for coo2 in iter(self): yield coo2.value def val(self) -> list[str | None]: # type: ignore[override] """Dict-like values() that returns a list of values of cookies from the jar. .. seealso:: keys() and items(). """ return list(self.ite2()) def ite3(self) -> Iterator[tuple[str, str | None]]: """Dict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues(). """ for coo3 in iter(self): yield coo3.name, coo3.value def ite4(self) -> list[tuple[str, str | None]]: # type: ignore[override] """Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a vanilla python dict of key value pairs. .. seealso:: keys() and values(). """ return list(self.ite3()) def list2(self) -> list[str]: """Utility method to list all the domains in the jar.""" dom2: list[str] = [] for coo4 in iter(self): if coo4.domain not in dom2: dom2.append(coo4.domain) return dom2 def list3(self) -> list[str]: """Utility method to list all the paths in the jar.""" pat2: list[str] = [] for coo5 in iter(self): if coo5.path not in pat2: pat2.append(coo5.path) return pat2 def multiple(self) -> bool: """Returns True if there are multiple domains in the jar. Returns False otherwise. :rtype: bool """ dom3: list[str] = [] for coo6 in iter(self): if coo6.domain is not None and coo6.domain in dom3: # type: ignore[reportUnnecessaryComparison] # defensive check return True dom3.append(coo6.domain) return False # there is only one domain in jar def get3( self, dom4: str | None = None, pat3: str | None = None ) -> dict[str, str | None]: """Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements. :rtype: dict """ dic: dict[str, str | None] = {} for coo7 in iter(self): if (dom4 is None or coo7.domain == dom4) and ( pat3 is None or coo7.path == pat3 ): dic[coo7.name] = coo7.value return dic def __iter__(self) -> Iterator[Cookie]: # type: ignore[override] """RequestCookieJar's __iter__ comes from CookieJar not MutableMapping.""" return super().__iter__() def __contains__(self, nam3: object) -> bool: try: return super().__contains__(nam3) except CookieConflictError: return True def __getitem__(self, nam4: str) -> str | None: """Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. .. warning:: operation is O(n), not O(1). """ return self.find(nam4) def __setitem__( self, nam5: str, val3: str | Morsel[dict[str, str]] | None ) -> None: """Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead. """ self.set2(nam5, val3) def __delitem__(self, nam6: str) -> None: """Deletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s ``remove_cookie_by_name()``. """ remove_cookie_by_name(self, nam6) def set3(self, coo8: Cookie, *arg: Any, **kwa2: Any) -> None: if ( (val4 := coo8.value) is not None and val4.startswith('"') and val4.endswith('"') ): coo8.value = val4.replace('\\"', "") return super().set_cookie(coo8, *arg, **kwa2) def upd( # type: ignore[override] self, oth: CookieJar | SupportsKeysAndGetItem[str, str] ) -> None: """Updates this jar with cookies from another CookieJar or dict-like""" if isinstance(oth, cookielib.CookieJar): for coo9 in oth: self.set3(copy.copy(coo9)) else: super().update(oth) def fin( self, nam7: str, dom5: str | None = None, pat4: str | None = None ) -> str | None: """Requests uses this method internally to get cookie values. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :return: cookie.value """ for coo10 in iter(self): if coo10.name == nam7: if dom5 is None or coo10.domain == dom5: if pat4 is None or coo10.path == pat4: return coo10.value raise KeyError(f"name={nam7!r}, domain={dom5!r}, path={pat4!r}") def find( self, nam8: str, dom6: str | None = None, pat5: str | None = None ) -> str: """Both ``__get_item__`` and ``get`` call this function: it's never used elsewhere in Requests. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :raises KeyError: if cookie is not found :raises CookieConflictError: if there are multiple cookies that match name and optionally domain and path :return: cookie.value """ to = None for coo11 in iter(self): if coo11.name == nam8: if dom6 is None or coo11.domain == dom6: if pat5 is None or coo11.path == pat5: if to is not None: # if there are multiple cookies that meet passed in criteria raise CookieConflictError( f"There are multiple cookies with name, {nam8!r}" ) # we will eventually return this as long as no cookie conflict to = coo11.value if to is not None: return to raise KeyError(f"name={nam8!r}, domain={dom6!r}, path={pat5!r}") def __getstate__(self) -> dict[str, Any]: """Unlike a normal CookieJar, this class is pickleable.""" sta = self.__dict__.copy() # remove the unpickleable RLock object sta.pop("_cookies_lock") return sta def __setstate__(self, sta2: dict[str, Any]) -> None: """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(sta2) if "_cookies_lock" not in self.__dict__: self._cookies_lock = threading.RLock() def cop(self) -> RequestsCookieJar: """Return a copy of this RequestsCookieJar.""" new = RequestsCookieJar() new.set_policy(self.get4()) new.update(self) return new def get4(self) -> CookiePolicy: """Return the CookiePolicy instance used.""" 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.9090.297−299.98
Source linesThe number of non-empty source lines.298+119.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.431−6.647

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.299−9.55
Indentation frequencyHow rapidly indentation changes from line to line.198+6.111
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.198−4.123
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.297.859+3.754
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.126.963−1.712
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.126.98+1.244
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.426

Intercept 0.07 + feature contributions = -3.78 (log-odds).
Score = sigmoid(-3.78) = 0.022.

Score0.604
Score145
Run 1

The code suffers from severe readability problems primarily due to non-descriptive, numbered identifiers (get2, set2, ite, ite2, ite3, ite4, list2, list3, get3, set3, upd, fin, get4) and similarly numbered parameter names (nam, nam2, nam3, etc.). This obscures intent and forces the reader to constantly cross-reference documentation. While the class structure is logical and methods are relatively short, the naming creates significant ambiguity. The nesting is moderate but acceptable, with conditional checks in 'find' and 'fin' being understandable. Action granularity is mostly maintained. The reading flow is disrupted by having to mentally track what each numbered variation does, which is especially problematic for methods like 'get2' vs 'get3' or 'list2' vs 'list3'.

Run 2

The code is highly obfuscated with meaningless, non-descriptive method and variable names like 'get2', 'set3', 'ite4', 'coo11', 'dom6', and 'pat5'. This completely obscures intent and violates basic readability principles. While the code structure is linear and nesting is moderate, the naming destroys clarity of intent. The method 'set3' does additional string processing and calls 'set_cookie', making it misleading. Action granularity varies; some methods have dense comprehensions while others are verbose loops. The reading flow is unnatural because readers must constantly decode abbreviated or numbered identifiers. Docstrings attempt to explain behavior, but they cannot compensate for the cryptic names. The code appears to be an intentionally degraded version of a readable class, with suffixes and generic imports adding noise.

Run 3

The code is significantly unreadable due to ambiguous, non-descriptive method names like get2, set2, ite, fin, and upd, which obscure intent. Naming conventions are inconsistent and heavily truncated, making it difficult to understand functionality. The structure follows a class-based organization but methods are arranged without logical grouping. Nesting is moderate but readability suffers due to defensive checks and multiple conditions. Some methods contain verbose comments while others lack clarity. The code is longer than necessary, with redundant loops and repeated patterns that could be refactored. Action granularity is acceptable, but the reading flow is disrupted by cryptic names and abbreviations. Overall, the code meets functional requirements but fails readability standards, as it does not communicate purpose clearly to a reader unfamiliar with the codebase.

Run 1

1. Code Structure: Methods are logically grouped within a cohesive cookie-jar class, but inconsistent naming obscures the API organization. 2. Nesting: Most methods are shallow; fin and find contain unnecessarily deep conditional chains. 3. Clarity of intent: Docstrings and type annotations help, but cryptic names such as ite3, get4, coo11, and to hinder understanding. Documentation references original method and parameter names rather than the actual identifiers, creating confusion. 4. Code length: Individual methods are generally concise, though repetitive iteration helpers and lengthy, sometimes mismatched docstrings increase reading effort. 5. Action granularity: Almost every line performs one action; the assignment expression in set3 adds modest complexity. 6. Reading flow: Consistent formatting and method separation support scanning, but numbered identifiers, misplaced threading import, and discrepancies between documented and implemented names disrupt natural reading.

Run 2

Code Structure: Methods are logically separated within a cohesive class, but inconsistent naming and import organization weaken structure. Nesting: Most methods are shallow, while fin and find contain unnecessarily deep conditional chains. Clarity of intent: Docstrings and type annotations explain cookie operations, but cryptic, numbered identifiers such as ite3, get4, and coo11 obscure meaning. Documentation often references original method names rather than the actual names, increasing confusion. Code length: Individual methods are generally concise, though repetitive wrappers and extensive boilerplate documentation make the class lengthy. Action granularity: Almost every line performs one clear action; the assignment expression in set3 adds minor complexity. Reading flow: Consistent formatting and related method grouping help, but arbitrary naming, mismatched documentation, and calls such as new.update versus the defined upd force readers to reconcile inconsistencies.

Run 3

1. Code Structure: Methods are logically separated within a cohesive cookie-jar class, though imports are poorly grouped. 2. Nesting: Most methods are shallow, but fin and find contain several nested conditionals that complicate scanning. 3. Clarity of intent: Docstrings and type annotations help substantially, but cryptic, numbered names such as ite3, get4, coo11, and nam8 obscure purpose. Documentation references original method and parameter names rather than actual ones, further confusing the interface. The multiple method's implementation also conflicts with its stated intent. 4. Code length: Individual implementations are generally concise, but repetitive wrappers and lengthy boilerplate documentation inflate the class. 5. Action granularity: Statements usually perform one action per line; the assignment expression in set3 is a minor exception. 6. Reading flow: Consistent formatting and method boundaries support navigation, but inconsistent naming and mismatched documentation force frequent cross-referencing.