Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1424: add keywords to the list of pythonic words #1425

Merged
merged 7 commits into from
Sep 13, 2021
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
3 changes: 2 additions & 1 deletion connexion/decorators/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import builtins
import functools
import inspect
import keyword
import logging
import re
from typing import Any
Expand Down Expand Up @@ -42,7 +43,7 @@ def snake_and_shadow(name):
:return:
"""
snake = inflection.underscore(name)
if snake in builtins.__dict__.keys():
if snake in builtins.__dict__ or keyword.iskeyword(snake):
return f"{snake}_"
return snake

Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def test_parameters_snake_case(snake_case_app):
assert resp.status_code == 200
resp = app_client.post('/v1.0/test-post-query-snake?someId=123', headers=headers, data=json.dumps({"a": "test"}))
assert resp.status_code == 200
resp = app_client.post('/v1.0/test-post-query-shadow?id=123', headers=headers, data=json.dumps({"a": "test"}))
resp = app_client.post('/v1.0/test-post-query-shadow?id=123&class=header', headers=headers, data=json.dumps({"a": "test"}))
assert resp.status_code == 200
resp = app_client.get('/v1.0/test-get-path-snake/123')
assert resp.status_code == 200
Expand Down
4 changes: 2 additions & 2 deletions tests/fakeapi/snake_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ def post_query_snake(some_id, some_other_id):
return data


def post_query_shadow(id_, next_):
data = {'id': id_, 'next': next_}
def post_query_shadow(id_, class_, next_):
data = {'id': id_, 'class': class_, 'next': next_}
return data
6 changes: 6 additions & 0 deletions tests/fixtures/snake_case/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ paths:
required: true
schema:
type: integer
- name: class
in: query
description: class parameter
required: true
schema:
type: string
requestBody:
content:
application/json:
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/snake_case/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ paths:
description: id parameter
required: true
type: integer
- name: class
in: query
description: class parameter
required: true
type: string
- name: next
in: body
description: next parameter
Expand Down