Skip to content

Commit 07a96ba

Browse files
authored
Merge pull request #351 from mik-laj/pyupgrade
Enforce latests syntax on CI
2 parents 246f52a + 0749e38 commit 07a96ba

File tree

24 files changed

+98
-47
lines changed

24 files changed

+98
-47
lines changed

.github/workflows/python-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
test:
13+
name: "Tests"
1314
runs-on: ubuntu-latest
1415
strategy:
1516
matrix:
@@ -31,3 +32,16 @@ jobs:
3132
run: python setup.py test
3233
- name: Upload coverage
3334
uses: codecov/codecov-action@v1
35+
36+
static-checks:
37+
name: "Static checks"
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
41+
uses: actions/checkout@v2
42+
- name: "Setup Python"
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: 3.9
46+
- name: "Run static checks"
47+
uses: pre-commit/action@v2.0.3

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
default_stages: [commit, push]
3+
default_language_version:
4+
# force all unspecified python hooks to run python3
5+
python: python3
6+
minimum_pre_commit_version: "1.20.0"
7+
repos:
8+
- repo: meta
9+
hooks:
10+
- id: check-hooks-apply
11+
- repo: https://github.com/asottile/pyupgrade
12+
rev: v2.19.0
13+
hooks:
14+
- id: pyupgrade
15+
args: ["--py36-plus"]
16+
- repo: local
17+
hooks:
18+
- id: flynt
19+
name: Convert to f-strings with flynt
20+
entry: flynt
21+
language: python
22+
additional_dependencies: ['flynt==0.64']

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Contributor Guide
3+
=================
4+
5+
# Static checks
6+
7+
The project uses static checks using fantastic [pre-commit](https://pre-commit.com/). Every change is checked on CI and if it does not pass the tests it cannot be accepted. If you want to check locally then run following command to install pre-commit:
8+
9+
```bash
10+
pip install -r requiremenets_dev.txt
11+
```
12+
13+
To turn on pre-commit checks for commit operations in git, enter:
14+
```bash
15+
pre-commit install
16+
```
17+
18+
To run all checks on your staged files, enter:
19+
```bash
20+
pre-commit run
21+
```
22+
23+
To run all checks on all files, enter:
24+
```bash
25+
pre-commit run --all-files
26+
```
27+
28+
Pre-commit check results are also attached to your PR through integration with Github Action.

openapi_core/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""OpenAPI core module"""
32
from openapi_core.shortcuts import (
43
create_spec, validate_request, validate_response,

openapi_core/casting/schemas/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ class CastError(OpenAPIError):
1010
type: str
1111

1212
def __str__(self):
13-
return "Failed to cast value to {type} type: {value}".format(
14-
type=self.type, value=self.value)
13+
return f"Failed to cast value to {self.type} type: {self.value}"

openapi_core/contrib/django/backports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def parse_header_name(cls, header):
2424

2525

2626
def request_current_scheme_host(req):
27-
return '{}://{}'.format(req.scheme, req.get_host())
27+
return f'{req.scheme}://{req.get_host()}'

openapi_core/deserializing/media_types/util.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ def data_form_loads(value):
1111
value = value.decode('ASCII', errors='surrogateescape')
1212
parser = Parser()
1313
parts = parser.parsestr(value, headersonly=False)
14-
return dict(
15-
(
16-
part.get_param('name', header='content-disposition'),
17-
part.get_payload(decode=True),
18-
)
14+
return {
15+
part.get_param('name', header='content-disposition'):
16+
part.get_payload(decode=True)
1917
for part in parts.get_payload()
20-
)
18+
}

openapi_core/deserializing/parameters/exceptions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class ParameterDeserializeError(BaseParameterDeserializeError):
1717

1818
def __str__(self):
1919
return (
20-
"Failed to deserialize value "
21-
"of {location} parameter with style {style}: {value}"
22-
).format(location=self.location, style=self.style, value=self.value)
20+
"Failed to deserialize value of "
21+
f"{self.location} parameter with style {self.style}: {self.value}"
22+
)
2323

2424

2525
@dataclass(init=False)
@@ -31,5 +31,6 @@ def __init__(self, name):
3131
self.name = name
3232

3333
def __str__(self):
34-
return "Value of {name} {location} parameter cannot be empty".format(
35-
name=self.name, location=self.location)
34+
return (
35+
f"Value of {self.name} {self.location} parameter cannot be empty"
36+
)

openapi_core/exceptions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ class MissingHeader(MissingHeaderError):
2323
name: str
2424

2525
def __str__(self):
26-
return "Missing header (without default value): {0}".format(
27-
self.name)
26+
return f"Missing header (without default value): {self.name}"
2827

2928

3029
@dataclass
3130
class MissingRequiredHeader(MissingHeaderError):
3231
name: str
3332

3433
def __str__(self):
35-
return "Missing required header: {0}".format(self.name)
34+
return f"Missing required header: {self.name}"
3635

3736

3837
class OpenAPIParameterError(OpenAPIError):
@@ -49,16 +48,15 @@ class MissingParameter(MissingParameterError):
4948
name: str
5049

5150
def __str__(self):
52-
return "Missing parameter (without default value): {0}".format(
53-
self.name)
51+
return f"Missing parameter (without default value): {self.name}"
5452

5553

5654
@dataclass
5755
class MissingRequiredParameter(MissingParameterError):
5856
name: str
5957

6058
def __str__(self):
61-
return "Missing required parameter: {0}".format(self.name)
59+
return f"Missing required parameter: {self.name}"
6260

6361

6462
class OpenAPIRequestBodyError(OpenAPIError):

openapi_core/security/providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ def __call__(self, request):
4040
scheme = self.scheme['scheme']
4141
if auth_type.lower() != scheme:
4242
raise SecurityError(
43-
'Unknown authorization method %s' % auth_type)
43+
f'Unknown authorization method {auth_type}')
4444

4545
return encoded_credentials

openapi_core/templating/media_types/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class MediaTypeNotFound(MediaTypeFinderError):
1616

1717
def __str__(self):
1818
return (
19-
"Content for the following mimetype not found: {0}. "
20-
"Valid mimetypes: {1}"
21-
).format(self.mimetype, self.availableMimetypes)
19+
f"Content for the following mimetype not found: {self.mimetype}. "
20+
f"Valid mimetypes: {self.availableMimetypes}"
21+
)

openapi_core/templating/paths/exceptions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PathNotFound(PathError):
1313
url: str
1414

1515
def __str__(self):
16-
return "Path not found for {0}".format(self.url)
16+
return f"Path not found for {self.url}"
1717

1818

1919
@dataclass
@@ -23,8 +23,7 @@ class OperationNotFound(PathError):
2323
method: str
2424

2525
def __str__(self):
26-
return "Operation {0} not found for {1}".format(
27-
self.method, self.url)
26+
return f"Operation {self.method} not found for {self.url}"
2827

2928

3029
@dataclass
@@ -33,4 +32,4 @@ class ServerNotFound(PathError):
3332
url: str
3433

3534
def __str__(self):
36-
return "Server not found for {0}".format(self.url)
35+
return f"Server not found for {self.url}"

openapi_core/templating/responses/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class ResponseNotFound(ResponseFinderError):
1616
availableresponses: List[str]
1717

1818
def __str__(self):
19-
return "Unknown response http status: {0}".format(
19+
return "Unknown response http status: {}".format(
2020
str(self.http_status))

openapi_core/templating/responses/finders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def find(self, http_status='default'):
1111
return self.responses / http_status
1212

1313
# try range
14-
http_status_range = '{0}XX'.format(http_status[0])
14+
http_status_range = f'{http_status[0]}XX'
1515
if http_status_range in self.responses:
1616
return self.responses / http_status_range
1717

openapi_core/unmarshalling/schemas/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ class FormatterNotFoundError(UnmarshallerError):
5454
type_format: str
5555

5656
def __str__(self):
57-
return "Formatter not found for {format} format".format(
58-
format=self.type_format)
57+
return f"Formatter not found for {self.type_format} format"

openapi_core/validation/request/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _get_parameter(self, param, request):
7878
deprecated = param.getkey('deprecated', False)
7979
if deprecated:
8080
warnings.warn(
81-
"{0} parameter is deprecated".format(name),
81+
f"{name} parameter is deprecated",
8282
DeprecationWarning,
8383
)
8484

openapi_core/validation/response/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _get_header(self, name, header, response):
114114
deprecated = header.getkey('deprecated', False)
115115
if deprecated:
116116
warnings.warn(
117-
"{0} header is deprecated".format(name),
117+
f"{name} header is deprecated",
118118
DeprecationWarning,
119119
)
120120

requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ webob
1111
strict-rfc3339==0.7
1212
sphinx==4.0.2
1313
sphinx-rtd-theme==0.5.2
14+
pre-commit

tests/integration/schema/test_link_spec.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import division
2-
31
from openapi_core.shortcuts import create_spec
42

53

tests/integration/schema/test_path_params.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import division
2-
31
import pytest
42

53
from openapi_core.shortcuts import create_spec

tests/integration/schema/test_spec.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division
21
import pytest
32
from base64 import b64encode
43

tests/integration/validation/test_petstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ def test_get_pet(self, spec, response_validator):
924924
}
925925
auth = 'authuser'
926926
headers = {
927-
'Authorization': 'Basic {auth}'.format(auth=auth),
927+
'Authorization': f'Basic {auth}',
928928
}
929929
request = MockRequest(
930930
host_url, 'GET', '/pets/1',

tests/unit/templating/test_paths_finders.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division
21
import pytest
32

43
from openapi_core.spec.paths import SpecPath
@@ -226,7 +225,7 @@ class BaseTestVariableValid:
226225

227226
@pytest.mark.parametrize('version', ['v1', 'v2'])
228227
def test_variable(self, finder, spec, version):
229-
request_uri = '/{0}/resource'.format(version)
228+
request_uri = f'/{version}/resource'
230229
method = 'get'
231230
request = MockRequest(
232231
'http://petstore.swagger.io', method, request_uri)
@@ -247,7 +246,7 @@ class BaseTestPathVariableValid:
247246

248247
@pytest.mark.parametrize('res_id', ['111', '222'])
249248
def test_path_variable(self, finder, spec, res_id):
250-
request_uri = '/resource/{0}'.format(res_id)
249+
request_uri = f'/resource/{res_id}'
251250
method = 'get'
252251
request = MockRequest(
253252
'http://petstore.swagger.io', method, request_uri)
@@ -476,7 +475,7 @@ def paths(self, path, path_2):
476475

477476
def test_valid(self, finder, spec):
478477
token_id = '123'
479-
request_uri = '/keys/{0}/tokens'.format(token_id)
478+
request_uri = f'/keys/{token_id}/tokens'
480479
method = 'get'
481480
request = MockRequest(
482481
'http://petstore.swagger.io', method, request_uri)
@@ -578,7 +577,7 @@ def paths(self, path, path_2):
578577

579578
def test_valid(self, finder, spec):
580579
token_id = '123'
581-
request_uri = '/keys/{0}/tokens/master'.format(token_id)
580+
request_uri = f'/keys/{token_id}/tokens/master'
582581
method = 'get'
583582
request = MockRequest(
584583
'http://petstore.swagger.io', method, request_uri)

tests/unit/templating/test_responses_finders.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import division
21
from unittest import mock
32

43
import pytest

0 commit comments

Comments
 (0)