Skip to content

Commit

Permalink
pincushion reserved names
Browse files Browse the repository at this point in the history
  • Loading branch information
canozyurt committed Aug 15, 2022
1 parent 69c51b5 commit 27b6359
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion maas/client/bones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import typing

from keyword import iskeyword

from collections import namedtuple
from collections.abc import Iterable
import json
Expand Down Expand Up @@ -173,7 +175,7 @@ def __populate(self):
self.__doc__ = self.__handler["doc"]
actions = self.__handler["actions"]
for action in actions:
setattr(self, action["name"], ActionAPI(action, self))
_setattr(self, action["name"], ActionAPI(action, self))

@property
def name(self):
Expand Down Expand Up @@ -515,3 +517,15 @@ def _prefer_json(headers):
if not any(header.lower() == "accept" for header in headers):
headers["Accept"] = "application/json,*/*;q=0.9"
return headers


def _setattr(obj, name, value):
"""Classic settatr(), also pincushions name if it's a reserved keyword.
Although keywords can be used as object names, they cause a syntax error
upon call. This renders ActionAPIs with names like 'import' unusable, thus
we pincushion the names.
"""
if iskeyword(name):
name = name + "_"
setattr(obj, name, value)

0 comments on commit 27b6359

Please sign in to comment.