Invalid use of keywords as variable names
chewr opened this issue · 0 comments
chewr commented
What happened?
conjure-python 3.13.3
I am consuming a conjure definition similar to this example. It produces invalid python code. The issue is the arg named from
which conflicts with the python keyword.
services:
SomeService:
endpoints:
getSomeResults:
args:
someRid:
type: identifiers.SomeRid
param-type: path
param-id: someRid
markers:
- Safe
limit:
docs: |
Limits the maximum number of results that will be returned in the response.
type: optional<integer>
param-type: query
param-id: limit
markers:
- Safe
from:
docs: Inclusively filters results based on startTime.
type: optional<datetime>
param-type: query
param-id: before
markers:
- Safe
returns: SomeReturnValue
This produced code similar to the following:
def get_some_results(self, auth_header, some_rid, from=None, limit=None):
# type: (str, str, Optional[str], Optional[int]) -> some_api_objects_SomeReturnValue
"""
Returns a SomeReturnValue for this thing. Results are in descending order by startTime
and contiguous pages can be loaded by using nextPageToken as the argument for before.
"""
_headers = {
'Accept': 'application/json',
'Authorization': auth_header,
} # type: Dict[str, Any]
_params = {
'limit': limit,
'before': from,
} # type: Dict[str, Any]
_path_params = {
'someRid': some_rid,
} # type: Dict[str, Any]
_json = None # type: Any
_path = '/some/path/{someRid}/stuff'
_path = _path.format(**_path_params)
_response = self._request( # type: ignore
'GET',
self._uri + _path,
params=_params,
headers=_headers,
json=_json)
_decoder = ConjureDecoder()
return _decoder.decode(_response.json(), some_api_objects_SomeReturnValue)
This client library causes compilation errors due to the use of from
, a reserved keyword, as a variable name
What did you want to happen?
Ideally the conjure-python generator could handle this case and transform names in the conjure spec in such a way that they do not collide with reserved keywords (e.g. naming the variable from_
or otherwise). The author of the conjure definition should obviously be allowed to be agnostic of this, as it is specific the downstream consumer.