Skip to content

Commit 961f975

Browse files
committed
Update pre-commit hooks and fix resulting linter warnings
1 parent a1a602f commit 961f975

10 files changed

Lines changed: 40 additions & 26 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
python-version:
16-
- "3.9"
17-
- "3.10"
1816
- "3.11"
1917
- "3.12"
2018
- "3.13"
19+
- "3.14"
2120
steps:
2221
- uses: actions/checkout@v4
2322
- name: Set up Python ${{ matrix.python-version }}

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.6.0
4+
rev: v6.0.0
55
hooks:
66
- id: check-yaml
77
- id: end-of-file-fixer
88
- id: trailing-whitespace
99
- repo: https://github.com/astral-sh/ruff-pre-commit
10-
rev: 'v0.5.0'
10+
rev: 'v0.15.12'
1111
hooks:
1212
- id: ruff
1313
- repo: https://github.com/pycqa/flake8
14-
rev: 7.1.0
14+
rev: 7.3.0
1515
hooks:
1616
- id: flake8
1717
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
@@ -29,7 +29,7 @@ repos:
2929
- id: pylint
3030
language: system
3131
- repo: https://github.com/pre-commit/mirrors-mypy
32-
rev: 'v1.10.1' # Use the sha / tag you want to point at
32+
rev: 'v1.20.2' # Use the sha / tag you want to point at
3333
hooks:
3434
- id: mypy
3535
args: [--explicit-package-bases]

doc/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
==== 2.8.0.dev ====
2+
* Fix I/O operation on closed file/buffer error in Response classes (#21)
3+
* Validate route filter definitions to reject spaces with clear error
4+
messages (#25)
5+
* Bad PATH_INFO encoding exception handling (#37, #38)
6+
* Updated openapi3.py example to openapi-core 0.23+ API (Spec replaced
7+
by OpenAPI)
8+
* Drop Python 3.9 and 3.10 support, require Python >= 3.11
9+
110
==== 2.7.0 ====
211
* Reserved Request.db attribute for usage
312
* Right HTTPException type annotation

examples/openapi3.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import logging as log
1515
import json
1616

17-
from openapi_core import (
18-
Spec,
19-
unmarshal_request, unmarshal_response,
20-
)
17+
from openapi_core import OpenAPI
2118

2219
from openapi_core.exceptions import OpenAPIError
2320
from openapi_core.templating.paths.exceptions import PathNotFound, \
@@ -56,7 +53,7 @@
5653

5754
with open(path.join(path.dirname(__file__), "openapi.json"),
5855
"r", encoding="utf-8") as openapi:
59-
app.openapi_spec = Spec.from_dict(json.load(openapi)) # type: ignore
56+
app.openapi_spec = OpenAPI.from_dict(json.load(openapi)) # type: ignore
6057

6158

6259
@app.before_response()
@@ -86,7 +83,8 @@ def before_each_response(req):
8683
"""Checks the API before processing each response."""
8784
req.api = OpenAPIRequest(req)
8885
try:
89-
unmarshal_request(req.api, app.openapi_spec)
86+
result = app.openapi_spec.unmarshal_request(req.api)
87+
result.raise_for_errors()
9088
except (OperationNotFound, PathNotFound) as error:
9189
log.debug("%s", error)
9290
return # not found
@@ -105,10 +103,10 @@ def after_each_response(req, res):
105103
if not hasattr(req, "api"):
106104
req.api = OpenAPIRequest(req)
107105
try:
108-
unmarshal_response(
106+
result = app.openapi_spec.unmarshal_response(
109107
req.api,
110-
OpenAPIResponse(res),
111-
app.openapi_spec)
108+
OpenAPIResponse(res))
109+
result.raise_for_errors()
112110
except (OperationNotFound, PathNotFound):
113111
return res
114112
except OpenAPIError as error:
@@ -170,6 +168,13 @@ def ajax_uuid(req, arg):
170168
return json.dumps({"arg": str(arg)}), "application/json"
171169

172170

171+
@app.route("/arg/<arg>")
172+
def ajax_arg_fallback(req, arg):
173+
"""Catch-all for /arg/{arg} - OpenAPI validation handles invalid types."""
174+
assert req
175+
return json.dumps({"arg": arg}), "application/json"
176+
177+
173178
@app.route('/internal-server-error')
174179
def method_raises_errror(req):
175180
"""Internal server error test."""

examples/simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import uwsgi # type: ignore
3939

4040
except ModuleNotFoundError:
41-
uwsgi = None # pylint: disable=invalid-name
41+
uwsgi = None # type: ignore[assignment] # pylint: disable=invalid-name
4242

4343
logger = log.getLogger()
4444
logger.setLevel("DEBUG")
@@ -275,7 +275,7 @@ def style(_):
275275
@app.route('/test/<variable:int>')
276276
@app.route('/test/<variable:uuid>')
277277
@app.route('/test/static')
278-
def test_dynamic(req, variable=None):
278+
def test_dynamic(req, variable=None): # noqa: PT028
279279
"""Tests dynamic values."""
280280
if not variable and req.headers.get('ETag') == 'W/"0123"':
281281
return not_modified(req)

poorwsgi/state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import warnings
99

1010
__author__ = "Ondrej Tuma (McBig) <mcbig@zeropage.cz>"
11-
__date__ = "14 Oct 2024"
11+
__date__ = "1 May 2026"
1212
# PEP 0386 -- Version Identification and Dependency Specification
13-
__version__ = "2.7.0"
13+
__version__ = "2.8.0.dev"
1414

1515
DECLINED = 0
1616

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def doc():
195195
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware",
196196
"Topic :: Software Development :: Libraries :: Python Modules"
197197
],
198-
python_requires=">=3.8",
198+
python_requires=">=3.11",
199199
cmdclass={
200200
'build_doc': BuildDoc,
201201
'clean_doc': CleanDoc,

tests_integrity/openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from email.message import Message
55
from urllib.parse import parse_qs, urlparse
66

7-
from openapi_core import Spec # type: ignore
7+
from openapi_core import OpenAPI # type: ignore
88
from openapi_core.validation.request.datatypes import ( # type: ignore
99
RequestParameters)
1010

@@ -83,7 +83,7 @@ def headers(self):
8383
def response_spec_json(filename):
8484
"""Initializes a response_validator for openapi.json."""
8585
with open(filename, "r", encoding="utf-8") as openapi:
86-
return Spec.from_dict(json.load(openapi))
86+
return OpenAPI.from_dict(json.load(openapi))
8787

8888

8989
__all__ = ["OpenAPIRequest", "OpenAPIResponse", "response_spec_json"]

tests_integrity/support.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from requests import Request, Session
1010
from requests.exceptions import RequestException
11-
from openapi_core import unmarshal_response
1211
from openapi_core.contrib.requests import (RequestsOpenAPIRequest,
1312
RequestsOpenAPIResponse)
1413
from openapi_core.exceptions import OpenAPIError
@@ -95,10 +94,10 @@ def check_api(url, method="GET", status_code=200,
9594
status_code = [status_code]
9695
assert response.status_code in status_code
9796
try:
98-
unmarshal_response(
97+
result = response_spec.unmarshal_response(
9998
RequestsOpenAPIRequest(request),
100-
RequestsOpenAPIResponse(response),
101-
response_spec)
99+
RequestsOpenAPIResponse(response))
100+
result.raise_for_errors()
102101
except PathNotFound:
103102
if response.status_code == 404:
104103
return response

tests_integrity/test_response_closed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def url(request):
2424
class TestResponseClosed:
2525
"""Test for Response with closed buffer handling."""
2626

27+
# pylint: disable=no-self-use
28+
2729
def test_simple_response(self, url):
2830
"""Test that a simple response works normally."""
2931
check_url(url+"/test")

0 commit comments

Comments
 (0)