Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3df404c

Browse files
authored
Merge pull request#2114 from python-gitlab/jlvillal/remove_trys
chore: simplify multi-nested try blocks
2 parentsbe33245 +e734470 commit3df404c

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

‎gitlab/base.py‎

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -101,47 +101,43 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
101101
self.__dict__["_module"]=importlib.import_module(module_name)
102102

103103
def__getattr__(self,name:str)->Any:
104-
try:
104+
ifnameinself.__dict__["_updated_attrs"]:
105105
returnself.__dict__["_updated_attrs"][name]
106-
exceptKeyError:
107-
try:
108-
value=self.__dict__["_attrs"][name]
109-
110-
# If the value is a list, we copy it in the _updated_attrs dict
111-
# because we are not able to detect changes made on the object
112-
# (append, insert, pop, ...). Without forcing the attr
113-
# creation __setattr__ is never called, the list never ends up
114-
# in the _updated_attrs dict, and the update() and save()
115-
# method never push the new data to the server.
116-
# See https://github.com/python-gitlab/python-gitlab/issues/306
117-
#
118-
# note: _parent_attrs will only store simple values (int) so we
119-
# don't make this check in the next except block.
120-
ifisinstance(value,list):
121-
self.__dict__["_updated_attrs"][name]=value[:]
122-
returnself.__dict__["_updated_attrs"][name]
123-
124-
returnvalue
125-
126-
exceptKeyError:
127-
try:
128-
returnself.__dict__["_parent_attrs"][name]
129-
exceptKeyErrorasexc:
130-
message= (
131-
f"{type(self).__name__!r} object has no attribute{name!r}"
132-
)
133-
ifself._created_from_list:
134-
message= (
135-
f"{message}\n\n"
136-
+textwrap.fill(
137-
f"{self.__class__!r} was created via a list() call and "
138-
f"only a subset of the data may be present. To ensure "
139-
f"all data is present get the object using a "
140-
f"get(object.id) call. For more details, see:"
141-
)
142-
+f"\n\n{_URL_ATTRIBUTE_ERROR}"
143-
)
144-
raiseAttributeError(message)fromexc
106+
107+
ifnameinself.__dict__["_attrs"]:
108+
value=self.__dict__["_attrs"][name]
109+
# If the value is a list, we copy it in the _updated_attrs dict
110+
# because we are not able to detect changes made on the object
111+
# (append, insert, pop, ...). Without forcing the attr
112+
# creation __setattr__ is never called, the list never ends up
113+
# in the _updated_attrs dict, and the update() and save()
114+
# method never push the new data to the server.
115+
# See https://github.com/python-gitlab/python-gitlab/issues/306
116+
#
117+
# note: _parent_attrs will only store simple values (int) so we
118+
# don't make this check in the next block.
119+
ifisinstance(value,list):
120+
self.__dict__["_updated_attrs"][name]=value[:]
121+
returnself.__dict__["_updated_attrs"][name]
122+
123+
returnvalue
124+
125+
ifnameinself.__dict__["_parent_attrs"]:
126+
returnself.__dict__["_parent_attrs"][name]
127+
128+
message=f"{type(self).__name__!r} object has no attribute{name!r}"
129+
ifself._created_from_list:
130+
message= (
131+
f"{message}\n\n"
132+
+textwrap.fill(
133+
f"{self.__class__!r} was created via a list() call and "
134+
f"only a subset of the data may be present. To ensure "
135+
f"all data is present get the object using a "
136+
f"get(object.id) call. For more details, see:"
137+
)
138+
+f"\n\n{_URL_ATTRIBUTE_ERROR}"
139+
)
140+
raiseAttributeError(message)
145141

146142
def__setattr__(self,name:str,value:Any)->None:
147143
self.__dict__["_updated_attrs"][name]=value

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp