Skip to content

Commit 6c76160

Browse files
hugovkwoodruffw
andauthored
Add support for Python 3.12 and drop EOL 3.6 and 3.7 (#323)
* Add support for Python 3.12 * Drop support for EOL Python 3.6 * Upgrade Python syntax with pyupgrade --py37-plus * examples, tests: reformat * cachecontrol, tox: run mypy on 3.12 and tweak ignores. --------- Co-authored-by: William Woodruff <[email protected]>
1 parent 783a338 commit 6c76160

19 files changed

+27
-38
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
contents: write
2020

2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323

2424
- uses: actions/setup-python@v4
2525
with:
26-
python-version: ">= 3.6"
26+
python-version: "3.x"
2727

2828
- name: deps
2929
run: python -m pip install -U build
@@ -35,7 +35,7 @@ jobs:
3535
uses: pypa/gh-action-pypi-publish@release/v1
3636

3737
- name: sign
38-
uses: sigstore/gh-action-sigstore-python@v1.2.3
38+
uses: sigstore/gh-action-sigstore-python@v2.0.1
3939
with:
4040
inputs: ./dist/*.tar.gz ./dist/*.whl
4141
release-signing-artifacts: true

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
19+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
2020
os: ["macos-latest", "windows-latest", "ubuntu-latest"]
2121

2222
steps:
23-
- uses: "actions/checkout@v3"
23+
- uses: "actions/checkout@v4"
2424
- uses: "actions/setup-python@v4"
2525
with:
2626
python-version: "${{ matrix.python-version }}"
27+
allow-prereleases: true
2728
- name: "Install dependencies"
2829
run: |
2930
python -VV

cachecontrol/adapter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,21 @@ def build_response(
125125
else:
126126
# Wrap the response file with a wrapper that will cache the
127127
# response when the stream has been consumed.
128-
response._fp = CallbackFileWrapper( # type: ignore[attr-defined]
129-
response._fp, # type: ignore[attr-defined]
128+
response._fp = CallbackFileWrapper( # type: ignore[assignment]
129+
response._fp, # type: ignore[arg-type]
130130
functools.partial(
131131
self.controller.cache_response, request, response
132132
),
133133
)
134134
if response.chunked:
135-
super_update_chunk_length = response._update_chunk_length # type: ignore[attr-defined]
135+
super_update_chunk_length = response._update_chunk_length
136136

137137
def _update_chunk_length(self: HTTPResponse) -> None:
138138
super_update_chunk_length()
139139
if self.chunk_left == 0:
140-
self._fp._close() # type: ignore[attr-defined]
140+
self._fp._close() # type: ignore[union-attr]
141141

142-
response._update_chunk_length = types.MethodType( # type: ignore[attr-defined]
142+
response._update_chunk_length = types.MethodType( # type: ignore[method-assign]
143143
_update_chunk_length, response
144144
)
145145

cachecontrol/caches/file_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class _FileCacheMixin:
6464

6565
def __init__(
6666
self,
67-
directory: Union[str, Path],
67+
directory: str | Path,
6868
forever: bool = False,
6969
filemode: int = 0o0600,
7070
dirmode: int = 0o0700,

cachecontrol/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def update_cached_response(
480480
cached_response.headers.update(
481481
{
482482
k: v
483-
for k, v in response.headers.items() # type: ignore[no-untyped-call]
483+
for k, v in response.headers.items()
484484
if k.lower() not in excluded_headers
485485
}
486486
)

cachecontrol/heuristics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def update_headers(self, response: HTTPResponse) -> dict[str, str]:
6868

6969
if "expires" not in response.headers:
7070
date = parsedate(response.headers["date"])
71-
expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[misc]
71+
expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[index,misc]
7272
headers["expires"] = datetime_to_header(expires)
7373
headers["cache-control"] = "public"
7474
return headers

cachecontrol/serialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def dumps(
3232
# also update the response with a new file handler to be
3333
# sure it acts as though it was never read.
3434
body = response.read(decode_content=False)
35-
response._fp = io.BytesIO(body) # type: ignore[attr-defined]
35+
response._fp = io.BytesIO(body) # type: ignore[assignment]
3636
response.length_remaining = len(body)
3737

3838
data = {
3939
"response": {
4040
"body": body, # Empty bytestring if body is stored separately
41-
"headers": {str(k): str(v) for k, v in response.headers.items()}, # type: ignore[no-untyped-call]
41+
"headers": {str(k): str(v) for k, v in response.headers.items()},
4242
"status": response.status,
4343
"version": response.version,
4444
"reason": str(response.reason),

docs/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# SPDX-FileCopyrightText: 2015 Eric Larson
42
#
53
# SPDX-License-Identifier: Apache-2.0

examples/benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313

1414
HOST = "localhost"
1515
PORT = 8050
16-
URL = "http://{}:{}/".format(HOST, PORT)
16+
URL = f"http://{HOST}:{PORT}/"
1717

1818

19-
class Server(object):
20-
19+
class Server:
2120
def __call__(self, env, sr):
2221
body = "Hello World!"
2322
status = "200 OK"
2423
headers = [
25-
("Cache-Control", "max-age=%i" % (60 * 10)), ("Content-Type", "text/plain")
24+
("Cache-Control", "max-age=%i" % (60 * 10)),
25+
("Content-Type", "text/plain"),
2626
]
2727
sr(status, headers)
2828
return body

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ classifiers = [
2424
"Environment :: Web Environment",
2525
"License :: OSI Approved :: Apache Software License",
2626
"Operating System :: OS Independent",
27-
"Programming Language :: Python :: 3.6",
2827
"Programming Language :: Python :: 3.7",
2928
"Programming Language :: Python :: 3.8",
3029
"Programming Language :: Python :: 3.9",
3130
"Programming Language :: Python :: 3.10",
3231
"Programming Language :: Python :: 3.11",
32+
"Programming Language :: Python :: 3.12",
3333
"Topic :: Internet :: WWW/HTTP",
3434
]
3535
keywords = ["requests", "http", "caching", "web"]

0 commit comments

Comments
 (0)