Skip to content
Myr

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

10 files+36 added−29 removed

modified:src/requests/__init__.py+2 added-2 removed
109 unmodified lines
110111# Check imported dependencies for compatibility.112try:113 check_compatibility(114 urllib3.__version__, # type: ignore[reportPrivateImportUsage]114 urllib3.__version__,115 chardet_version,116 charset_normalizer_version,117 )118except (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 lines
modified:src/requests/adapters.py+2 added-2 removed
7 unmodified lines
89from __future__ import annotations1011import os.path12import socket # noqa: F401 # type: ignore[reportUnusedImport]12import socket # noqa: F40113import typing14import warnings15from typing import Any16
15 unmodified lines
32from urllib3.util import Timeout as TimeoutSauce33from urllib3.util import parse_url34from urllib3.util.retry import Retry3536from .auth import _basic_auth_str # type: ignore[reportPrivateUsage]36from .auth import _basic_auth_str37from .compat import basestring, urlparse38from .cookies import extract_cookies_to_jar39from .exceptions import (40 ConnectionError,
708 unmodified lines
modified:src/requests/auth.py+3 added-3 removed
39 unmodified lines
40 # - 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 line
50 category=DeprecationWarning,51 )52 username = str(username)5354 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 lines
299 # 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)306307 _digest_auth = self.build_digest_header(
47 unmodified lines
modified:src/requests/compat.py+1 added-3 removed
17 unmodified lines
1819# -------20# urllib321# -------22from urllib3 import (23 __version__ as urllib3_version, # type: ignore[reportPrivateImportUsage]24)22from urllib3 import __version__ as urllib3_version2324# Detect which major version of urllib3 is being used.25try:26 is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
89 unmodified lines
modified:src/requests/cookies.py+1 added-1 removed
608 unmodified lines
609 :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")615616 if isinstance(cookies, dict):617 cookiejar = cookiejar_from_dict(cookies, cookiejar=cookiejar, overwrite=False)
8 unmodified lines
modified:src/requests/help.py+1 added-1 removed
76 unmodified lines
77 "release": "Unknown",78 }7980 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 lines
modified:src/requests/models.py+9 added-5 removed
10 unmodified lines
1112# 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.15import encodings.idna # noqa: F401 # type: ignore[reportUnusedImport]15import encodings.idna # noqa: F40116from collections.abc import Callable, Generator, Iterable, Iterator, Mapping17from io import UnsupportedOperation18from typing import (19 TYPE_CHECKING,
29 unmodified lines
49 urlunparse,50)51from .compat import json as complexjson52from .cookies import (53 _copy_cookie_jar, # type: ignore[reportPrivateUsage]53 _copy_cookie_jar,54 cookiejar_from_dict,55 get_cookie_header,56)57from .exceptions import (
177 unmodified lines
235 fp = v236237 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 lines
265266 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 filter272273 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 lines
957 self._content_consumed = True958959 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 lines
modified:src/requests/sessions.py+5 added-5 removed
17 unmodified lines
1819from ._internal_utils import to_native_string20from ._types import is_prepared as _is_prepared21from .adapters import HTTPAdapter22from .auth import _basic_auth_str # type: ignore[reportPrivateUsage]22from .auth import _basic_auth_str23from .compat import cookielib, urljoin, urlparse24from .cookies import (25 RequestsCookieJar,26 cookiejar_from_dict,
10 unmodified lines
3738# formerly defined here, reexposed here for backward compatibility39from .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 lines
53 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)6061if TYPE_CHECKING:
200 unmodified lines
262263 # 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 lines
274275 # 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 )281282 # Attempt to rewind consumed file-like object.
638 unmodified lines
modified:src/requests/utils.py+7 added-7 removed
35 unmodified lines
36from .__version__ import __version__3738# to_native_string is unused here, but imported here for backwards compatibility39from ._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)45from ._types import SupportsItems as _SupportsItems46from .compat import (47 Mapping,
1053 unmodified lines
1101 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 lines
1141 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 lines
modified:pyproject.toml+5 added
116 unmodified lines
117118[tool.pyright]119include = ["src/requests"]120typeCheckingMode = "strict"121# linting rules unrelated to type checking122reportPrivateUsage = false123reportPrivateImportUsage = false124reportUnnecessaryIsInstance = false125reportUnusedImport = false # duplicate of Ruff's F401 rule