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/[email protected]

.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

0 commit comments

Comments
 (0)