Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev", "pypy-3.10", "pypy-3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev", "pypy-3.11"]
os: [ubuntu-22.04, macOS-latest, windows-latest]
# Pypy-3.11 can't install openssl-sys with rust
# which prevents us from testing in GHA.
Expand Down
22 changes: 5 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,12 @@ repos:
rev: v4.4.0
hooks:
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- id: ruff
args: [--fix]
- id: ruff-format
exclude: tests/test_lowlevel.py
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
28 changes: 24 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
[tool.isort]
profile = "black"
src_paths = ["src/requests", "test"]
honor_noqa = true
[tool.ruff]
target-version = "py310"
src = ["src/requests", "tests"]
exclude = ["docs/", "ext/"]

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"T10", # flake8-debugger (replaces debug-statements hook)
]
ignore = ["E203", "E501", "UP038", "UP031"]
per-file-ignores = {"src/requests/__init__.py" = ["E402", "F401"], "src/requests/compat.py" = ["E402", "F401"], "tests/compat.py" = ["F401"]}

[tool.ruff.lint.isort]
known-first-party = ["requests"]

[tool.ruff.format]
# Use black-compatible formatting
quote-style = "double"
indent-style = "space"

[tool.pytest.ini_options]
addopts = "--doctest-modules"
Expand Down
7 changes: 0 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,3 @@ requires-dist =
charset_normalizer>=2,<4
idna>=2.5,<4
urllib3>=1.21.1,<3

[flake8]
ignore = E203, E501, W503
per-file-ignores =
src/requests/__init__.py:E402, F401
src/requests/compat.py:E402, F401
tests/compat.py:F401
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

If you can't upgrade your Python version, you'll need to
pin to an older version of Requests (<2.32.0).
""".format(
*(REQUIRED_PYTHON + CURRENT_PYTHON)
)
""".format(*(REQUIRED_PYTHON + CURRENT_PYTHON))
)
sys.exit(1)

Expand Down
11 changes: 5 additions & 6 deletions src/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def _check_cryptography(cryptography_version):
return

if cryptography_version < [1, 3, 4]:
warning = "Old version of cryptography ({}) may cause slowdown.".format(
cryptography_version
warning = (
f"Old version of cryptography ({cryptography_version}) may cause slowdown."
)
warnings.warn(warning, RequestsDependencyWarning)

Expand All @@ -111,10 +111,9 @@ def _check_cryptography(cryptography_version):
)
except (AssertionError, ValueError):
warnings.warn(
"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
"version!".format(
urllib3.__version__, chardet_version, charset_normalizer_version
),
f"urllib3 ({urllib3.__version__}) or chardet "
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
"doesn't match a supported version!",
RequestsDependencyWarning,
)

Expand Down
1 change: 1 addition & 0 deletions src/requests/_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Provides utility functions that are consumed internally by Requests
which depend on extremely few external helpers (such as compat)
"""

import re

from .compat import builtin_str
Expand Down
14 changes: 8 additions & 6 deletions src/requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
import typing
import warnings

from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
from urllib3.exceptions import HTTPError as _HTTPError
from urllib3.exceptions import InvalidHeader as _InvalidHeader
from urllib3.exceptions import (
ClosedPoolError,
ConnectTimeoutError,
LocationValueError,
MaxRetryError,
NewConnectionError,
ProtocolError,
ReadTimeoutError,
ResponseError,
)
from urllib3.exceptions import HTTPError as _HTTPError
from urllib3.exceptions import InvalidHeader as _InvalidHeader
from urllib3.exceptions import ProxyError as _ProxyError
from urllib3.exceptions import ReadTimeoutError, ResponseError
from urllib3.exceptions import SSLError as _SSLError
from urllib3.poolmanager import PoolManager, proxy_from_url
from urllib3.util import Timeout as TimeoutSauce
Expand Down Expand Up @@ -76,9 +78,9 @@ def SOCKSProxyManager(*args, **kwargs):
def _urllib3_request_context(
request: "PreparedRequest",
verify: "bool | str | None",
client_cert: "typing.Tuple[str, str] | str | None",
client_cert: "tuple[str, str] | str | None",
poolmanager: "PoolManager",
) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])":
) -> "(dict[str, typing.Any], dict[str, typing.Any])":
host_params = {}
pool_kwargs = {}
parsed_request_url = urlparse(request.url)
Expand Down
8 changes: 4 additions & 4 deletions src/requests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ def _basic_auth_str(username, password):
if not isinstance(username, basestring):
warnings.warn(
"Non-string usernames will no longer be supported in Requests "
"3.0.0. Please convert the object you've passed in ({!r}) to "
f"3.0.0. Please convert the object you've passed in ({username!r}) to "
"a string or bytes object in the near future to avoid "
"problems.".format(username),
"problems.",
category=DeprecationWarning,
)
username = str(username)

if not isinstance(password, basestring):
warnings.warn(
"Non-string passwords will no longer be supported in Requests "
"3.0.0. Please convert the object you've passed in ({!r}) to "
f"3.0.0. Please convert the object you've passed in ({type(password)!r}) to "
"a string or bytes object in the near future to avoid "
"problems.".format(type(password)),
"problems.",
category=DeprecationWarning,
)
password = str(password)
Expand Down
1 change: 1 addition & 0 deletions src/requests/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
environment, you can change the definition of where() to return a separately
packaged CA bundle.
"""

from certifi import where

if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions src/requests/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

This module contains the set of Requests' exceptions.
"""

from urllib3.exceptions import HTTPError as BaseHTTPError

from .compat import JSONDecodeError as CompatJSONDecodeError
Expand Down
7 changes: 2 additions & 5 deletions src/requests/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ def _implementation():
if implementation == "CPython":
implementation_version = platform.python_version()
elif implementation == "PyPy":
implementation_version = "{}.{}.{}".format(
sys.pypy_version_info.major,
sys.pypy_version_info.minor,
sys.pypy_version_info.micro,
)
pypy = sys.pypy_version_info
implementation_version = f"{pypy.major}.{pypy.minor}.{pypy.micro}"
if sys.pypy_version_info.releaselevel != "final":
implementation_version = "".join(
[implementation_version, sys.pypy_version_info.releaselevel]
Expand Down
1 change: 1 addition & 0 deletions src/requests/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
``response``:
The response generated from a Request.
"""

HOOKS = ["response"]


Expand Down
8 changes: 5 additions & 3 deletions src/requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
builtin_str,
chardet,
cookielib,
urlencode,
urlsplit,
urlunparse,
)
from .compat import json as complexjson
from .compat import urlencode, urlsplit, urlunparse
from .cookies import _copy_cookie_jar, cookiejar_from_dict, get_cookie_header
from .exceptions import (
ChunkedEncodingError,
Expand All @@ -45,11 +47,11 @@
HTTPError,
InvalidJSONError,
InvalidURL,
MissingSchema,
StreamConsumedError,
)
from .exceptions import JSONDecodeError as RequestsJSONDecodeError
from .exceptions import MissingSchema
from .exceptions import SSLError as RequestsSSLError
from .exceptions import StreamConsumedError
from .hooks import default_hooks
from .status_codes import codes
from .structures import CaseInsensitiveDict
Expand Down
1 change: 1 addition & 0 deletions src/requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
"""

import os
import sys
import time
Expand Down
4 changes: 1 addition & 3 deletions src/requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
getproxies_environment,
integer_types,
is_urllib3_1,
)
from .compat import parse_http_list as _parse_list_header
from .compat import (
proxy_bypass,
proxy_bypass_environment,
quote,
Expand All @@ -50,6 +47,7 @@
urlparse,
urlunparse,
)
from .compat import parse_http_list as _parse_list_header
from .cookies import cookiejar_from_dict
from .exceptions import (
FileModeWarning,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lowlevel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import threading

import pytest
from tests.testserver.server import Server, consume_socket_content

import requests
from requests.compat import JSONDecodeError
from tests.testserver.server import Server, consume_socket_content

from .utils import override_environ

Expand Down
19 changes: 9 additions & 10 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
ReadTimeout,
RequestException,
RetryError,
Timeout,
TooManyRedirects,
UnrewindableBodyError,
)
from requests.exceptions import SSLError as RequestsSSLError
from requests.exceptions import Timeout, TooManyRedirects, UnrewindableBodyError
from requests.hooks import default_hooks
from requests.models import PreparedRequest, urlencode
from requests.sessions import SessionRedirectMixin
Expand Down Expand Up @@ -960,20 +962,18 @@ def test_invalid_ca_certificate_path(self, httpbin_secure):
INVALID_PATH = "/garbage"
with pytest.raises(IOError) as e:
requests.get(httpbin_secure(), verify=INVALID_PATH)
assert str(
e.value
) == "Could not find a suitable TLS CA certificate bundle, invalid path: {}".format(
INVALID_PATH
assert (
str(e.value)
== f"Could not find a suitable TLS CA certificate bundle, invalid path: {INVALID_PATH}"
)

def test_invalid_ssl_certificate_files(self, httpbin_secure):
INVALID_PATH = "/garbage"
with pytest.raises(IOError) as e:
requests.get(httpbin_secure(), cert=INVALID_PATH)
assert str(
e.value
) == "Could not find the TLS certificate file, invalid path: {}".format(
INVALID_PATH
assert (
str(e.value)
== f"Could not find the TLS certificate file, invalid path: {INVALID_PATH}"
)

with pytest.raises(IOError) as e:
Expand Down Expand Up @@ -2460,7 +2460,6 @@ def test_expires_none(self):


class TestMorselToCookieMaxAge:

"""Tests for morsel_to_cookie when morsel contains max-age."""

def test_max_age_valid_int(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import time

import pytest
from tests.testserver.server import Server

import requests
from tests.testserver.server import Server


class TestTestServer:
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_server_closes(self):
def test_text_response(self):
"""the text_response_server sends the given text"""
server = Server.text_response_server(
"HTTP/1.1 200 OK\r\n" "Content-Length: 6\r\n" "\r\nroflol"
"HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\nroflol"
)

with server as (host, port):
Expand Down
Loading