10000 Pass kwargs to object factory by hakkeroid · Pull Request #168 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

Pass kwargs to object factory #168

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

Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ MANIFEST
.idea/
docs/_build
.testrepository/
.tox
13 changes: 7 additions & 6 deletions gitlab/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,26 @@ def get(cls, gl, id, **kwargs):

raise GitlabGetError("Object not found")

def _get_object(self, k, v):
def _get_object(self, k, v, **kwargs):
if self._constructorTypes and k in self._constructorTypes:
return globals()[self._constructorTypes[k]](self.gitlab, v)
return globals()[self._constructorTypes[k]](self.gitlab, v,
**kwargs)
else:
return v

def _set_from_dict(self, data):
def _set_from_dict(self, data, **kwargs):
if not hasattr(data, 'items'):
return

for k, v in data.items():
if isinstance(v, list):
self.__dict__[k] = []
for i in v:
self.__dict__[k].append(self._get_object(k, i))
self.__dict__[k].append(self._get_object(k, i, **kwargs))
elif v is None:
self.__dict__[k] = None
else:
self.__dict__[k] = self._get_object(k, v)
self.__dict__[k] = self._get_object(k, v, **kwargs)

def _create(self, **kwargs):
if not self.canCreate:
Expand Down Expand Up @@ -377,7 +378,7 @@ def __init__(self, gl, data=None, **kwargs):
data = self.gitlab.get(self.__class__, data, **kwargs)
self._from_api = True

self._set_from_dict(data)
self._set_from_dict(data, **kwargs)

if kwargs:
for k, v in kwargs.items():
Expand Down
0