Disable commonly ignored Pyright linting rules (#7497)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Joren Hammudoglu · committed by GitHub · parent fbd0eb3 · Browse files · 10 files·+36 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+36 added−29 removed
- other:+36 added−29 removed
Provenance
- Commit
661970d- Tree
ea72ddd- Author
Joren Hammudoglu <jhammudoglu@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
fbd0eb3
10 files changed+36 added−29 removed
modified:src/requests/__init__.py+2 added-2 removed
109 unmodified lines110 111 # Check imported dependencies for compatibility.112 try:113 check_compatibility(114- urllib3.__version__, # type: ignore[reportPrivateImportUsage]114+ urllib3.__version__,115 chardet_version,116 charset_normalizer_version,117 )118 except (AssertionError, ValueError):119 warnings.warn(120- f"urllib3 ({urllib3.__version__}) or chardet " # type: ignore[reportPrivateImportUsage]120+ f"urllib3 ({urllib3.__version__}) or chardet "121 f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "122 "doesn't match a supported version!",123 RequestsDependencyWarning,124 )95 unmodified linesmodified:src/requests/adapters.py+2 added-2 removed
7 unmodified lines8 9 from __future__ import annotations10 11 import os.path12-import socket # noqa: F401 # type: ignore[reportUnusedImport]12+import socket # noqa: F40113 import typing14 import warnings15 from typing import Any16 15 unmodified lines32 from urllib3.util import Timeout as TimeoutSauce33 from urllib3.util import parse_url34 from urllib3.util.retry import Retry35 36-from .auth import _basic_auth_str # type: ignore[reportPrivateUsage]36+from .auth import _basic_auth_str37 from .compat import basestring, urlparse38 from .cookies import extract_cookies_to_jar39 from .exceptions import (40 ConnectionError,708 unmodified linesmodified:src/requests/auth.py+3 added-3 removed
39 unmodified lines40 # - Lukasa41 #42 # These are here solely to maintain backwards compatibility43 # for things like ints. This will be removed in 3.0.0.44- if not isinstance(username, basestring): # type: ignore[reportUnnecessaryIsInstance] # runtime guard for non-str/bytes44+ if not isinstance(username, basestring): # runtime guard for non-str/bytes45 warnings.warn(46 "Non-string usernames will no longer be supported in Requests "47 f"3.0.0. Please convert the object you've passed in ({username!r}) to "48 "a string or bytes object in the near future to avoid "1 unmodified line50 category=DeprecationWarning,51 )52 username = str(username)53 54- if not isinstance(password, basestring): # type: ignore[reportUnnecessaryIsInstance] # runtime guard for non-str/bytes54+ if not isinstance(password, basestring): # runtime guard for non-str/bytes55 warnings.warn(56 "Non-string passwords will no longer be supported in Requests "57 f"3.0.0. Please convert the object you've passed in ({type(password)!r}) to "58 "a string or bytes object in the near future to avoid "240 unmodified lines299 # to allow our new request to reuse the same one.300 r.content301 r.close()302 prep = r.request.copy()303- cookie_jar = cast("CookieJar", prep._cookies) # type: ignore[reportPrivateUsage]303+ cookie_jar = cast("CookieJar", prep._cookies)304 extract_cookies_to_jar(cookie_jar, r.request, r.raw)305 prep.prepare_cookies(cookie_jar)306 307 _digest_auth = self.build_digest_header(47 unmodified linesmodified:src/requests/compat.py+1 added-3 removed
17 unmodified lines18 19 # -------20 # urllib321 # -------22-from urllib3 import (23- __version__ as urllib3_version, # type: ignore[reportPrivateImportUsage]24-)22+from urllib3 import __version__ as urllib3_version23 24 # Detect which major version of urllib3 is being used.25 try:26 is_urllib3_1 = int(urllib3_version.split(".")[0]) == 189 unmodified linesmodified:src/requests/cookies.py+1 added-1 removed
608 unmodified lines609 :param cookiejar: CookieJar object to add the cookies to.610 :param cookies: Dictionary or CookieJar object to be added.611 :rtype: CookieJar612 """613- if not isinstance(cookiejar, cookielib.CookieJar): # type: ignore[reportUnnecessaryIsInstance] # runtime guard613+ if not isinstance(cookiejar, cookielib.CookieJar): # runtime guard614 raise ValueError("You can only merge into CookieJar")615 616 if isinstance(cookies, dict):617 cookiejar = cookiejar_from_dict(cookies, cookiejar=cookiejar, overwrite=False)8 unmodified linesmodified:src/requests/help.py+1 added-1 removed
76 unmodified lines77 "release": "Unknown",78 }79 80 implementation_info = _implementation()81- urllib3_info = {"version": urllib3.__version__} # type: ignore[reportPrivateImportUsage]81+ urllib3_info = {"version": urllib3.__version__}82 charset_normalizer_info = {"version": None}83 chardet_info: dict[str, str | None] = {"version": None}84 if charset_normalizer:85 charset_normalizer_info = {"version": charset_normalizer.__version__}47 unmodified linesmodified:src/requests/models.py+9 added-5 removed
10 unmodified lines11 12 # Import encoding now, to avoid implicit import later.13 # Implicit import within threads may cause LookupError when standard library is in a ZIP,14 # such as in Embedded Python. See https://github.com/psf/requests/issues/3578.15-import encodings.idna # noqa: F401 # type: ignore[reportUnusedImport]15+import encodings.idna # noqa: F40116 from collections.abc import Callable, Generator, Iterable, Iterator, Mapping17 from io import UnsupportedOperation18 from typing import (19 TYPE_CHECKING,29 unmodified lines49 urlunparse,50 )51 from .compat import json as complexjson52 from .cookies import (53- _copy_cookie_jar, # type: ignore[reportPrivateUsage]53+ _copy_cookie_jar,54 cookiejar_from_dict,55 get_cookie_header,56 )57 from .exceptions import (177 unmodified lines235 fp = v236 237 if isinstance(fp, (str, bytes, bytearray)):238 fdata = fp239- elif isinstance(fp, _SupportsRead): # type: ignore[reportUnnecessaryIsInstance] # defensive check for untyped callers239+ elif isinstance(fp, _SupportsRead): # defensive check for untyped callers240 fdata = fp.read()241 elif fp is None: # defensive check for untyped callers242 continue243 else:21 unmodified lines265 266 if isinstance(hook, Callable):267 self.hooks[event].append(hook)268 elif hasattr(hook, "__iter__"):269- self.hooks[event].extend(h for h in hook if isinstance(h, Callable)) # type: ignore[reportUnnecessaryIsInstance] # defensive runtime filter269+ self.hooks[event].extend(270+ h for h in hook if isinstance(h, Callable)271+ ) # defensive runtime filter272 273 def deregister_hook(self, event: str, hook: _t.HookType) -> bool:274 """Deregister a previously registered hook.275 Returns True if the hook existed, False if not.681 unmodified lines957 self._content_consumed = True958 959 if self._content_consumed and isinstance(self._content, bool):960 raise StreamConsumedError()959- elif chunk_size is not None and not isinstance(chunk_size, int): # type: ignore[reportUnnecessaryIsInstance] # runtime guard for untyped callers961+ elif chunk_size is not None and not isinstance(962+ chunk_size, int963+ ): # runtime guard for untyped callers964 raise TypeError(965 f"chunk_size must be an int, it is instead a {type(chunk_size)}."966 )967 218 unmodified linesmodified:src/requests/sessions.py+5 added-5 removed
17 unmodified lines18 19 from ._internal_utils import to_native_string20 from ._types import is_prepared as _is_prepared21 from .adapters import HTTPAdapter22-from .auth import _basic_auth_str # type: ignore[reportPrivateUsage]22+from .auth import _basic_auth_str23 from .compat import cookielib, urljoin, urlparse24 from .cookies import (25 RequestsCookieJar,26 cookiejar_from_dict,10 unmodified lines37 38 # formerly defined here, reexposed here for backward compatibility39 from .models import ( # noqa: F40140 DEFAULT_REDIRECT_LIMIT,41- REDIRECT_STATI, # type: ignore[reportUnusedImport]41+ REDIRECT_STATI,42 PreparedRequest,43 Request,44 Response,45 )7 unmodified lines53 get_netrc_auth,54 requote_uri,55 resolve_proxies,56 rewind_body,57- should_bypass_proxies, # type: ignore[reportUnusedImport] # re-export for external consumers57+ should_bypass_proxies, # re-export for external consumers58 to_key_val_list,59 )60 61 if TYPE_CHECKING:200 unmodified lines262 263 # Extract any cookies sent on the response to the cookiejar264 # in the new request. Because we've mutated our copied prepared265 # request, use the old one that we haven't yet touched.266- cookie_jar = cast("CookieJar", prepared_request._cookies) # type: ignore[reportPrivateUsage]266+ cookie_jar = cast("CookieJar", prepared_request._cookies)267 extract_cookies_to_jar(cookie_jar, req, resp.raw)268 merge_cookies(cookie_jar, self.cookies)269 prepared_request.prepare_cookies(cookie_jar)270 3 unmodified lines274 275 # A failed tell() sets `_body_position` to `object()`. This non-None276 # value ensures `rewindable` will be True, allowing us to raise an277 # UnrewindableBodyError, instead of hanging the connection.278- rewindable = prepared_request._body_position is not None and ( # type: ignore[reportPrivateUsage]278+ rewindable = prepared_request._body_position is not None and (279 "Content-Length" in headers or "Transfer-Encoding" in headers280 )281 282 # Attempt to rewind consumed file-like object.638 unmodified linesmodified:src/requests/utils.py+7 added-7 removed
35 unmodified lines36 from .__version__ import __version__37 38 # to_native_string is unused here, but imported here for backwards compatibility39 from ._internal_utils import ( # noqa: F40140- _HEADER_VALIDATORS_BYTE, # type: ignore[reportPrivateUsage]41- _HEADER_VALIDATORS_STR, # type: ignore[reportPrivateUsage]42- HEADER_VALIDATORS, # type: ignore[reportUnusedImport]43- to_native_string, # type: ignore[reportUnusedImport]40+ _HEADER_VALIDATORS_BYTE,41+ _HEADER_VALIDATORS_STR,42+ HEADER_VALIDATORS,43+ to_native_string,44 )45 from ._types import SupportsItems as _SupportsItems46 from .compat import (47 Mapping,1053 unmodified lines1101 header_validator_index: int,1102 ) -> None:1103 if isinstance(header_part, str):1104 validator = _HEADER_VALIDATORS_STR[header_validator_index]1105- elif isinstance(header_part, bytes): # type: ignore[reportUnnecessaryIsInstance]1105+ elif isinstance(header_part, bytes):1106 # runtime guard for non-str/bytes input1107 validator = _HEADER_VALIDATORS_BYTE[header_validator_index]1108 else:1109 raise InvalidHeader(31 unmodified lines1141 so it can be read again on redirect.1142 """1143 body_seek = getattr(prepared_request.body, "seek", None)1144 if body_seek is not None and isinstance(1145- prepared_request._body_position, # type: ignore[reportPrivateUsage]1145+ prepared_request._body_position,1146 integer_types,1147 ):1148 try:1149- body_seek(prepared_request._body_position) # type: ignore[reportPrivateUsage]1149+ body_seek(prepared_request._body_position)1150 except OSError:1151 raise UnrewindableBodyError(1152 "An error occurred when rewinding request body for redirect."1153 )2 unmodified linesmodified:pyproject.toml+5 added
116 unmodified lines117 118 [tool.pyright]119 include = ["src/requests"]120 typeCheckingMode = "strict"121+# linting rules unrelated to type checking122+reportPrivateUsage = false123+reportPrivateImportUsage = false124+reportUnnecessaryIsInstance = false125+reportUnusedImport = false # duplicate of Ruff's F401 rule