Skip to content

Commit 05a35c3

Browse files
committed
Add docstrings to __setattr__ and __getattr__ methods in EventFiringWebDriver and EventFiringWebElement classes for clarity on functionality
1 parent 25e8ebc commit 05a35c3

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

py/selenium/webdriver/support/event_firing_webdriver.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ def _wrap_value(self, value):
135135
return WebDriver._wrap_value(self._driver, value)
136136

137137
def __setattr__(self, item, value):
138+
"""Set an attribute on the EventFiringWebDriver or wrapped driver.
139+
140+
Sets internal attributes (those starting with '_') on this instance.
141+
Other attributes are delegated to the wrapped driver. Exceptions
142+
are reported to the listener.
143+
144+
Args:
145+
item: The attribute name.
146+
value: The attribute value.
147+
148+
Raises:
149+
Exception: Any exception from the wrapped driver is re-raised
150+
after being reported to the listener.
151+
"""
138152
if item.startswith("_") or not hasattr(self._driver, item):
139153
object.__setattr__(self, item, value)
140154
else:
@@ -145,6 +159,22 @@ def __setattr__(self, item, value):
145159
raise
146160

147161
def __getattr__(self, name):
162+
"""Get an attribute from the wrapped driver.
163+
164+
Wraps returned WebElement objects and callable attributes. Exceptions
165+
are reported to the listener.
166+
167+
Args:
168+
name: The attribute name.
169+
170+
Returns:
171+
The attribute value from the wrapped driver, with WebElement
172+
objects wrapped and callables wrapped to report exceptions.
173+
174+
Raises:
175+
Exception: Any exception from the wrapped driver is re-raised
176+
after being reported to the listener.
177+
"""
148178
def _wrap(*args, **kwargs):
149179
try:
150180
result = attrib(*args, **kwargs)
@@ -205,6 +235,20 @@ def _dispatch(self, l_call, l_args, d_call, d_args):
205235
return _wrap_elements(result, self._ef_driver)
206236

207237
def __setattr__(self, item, value):
238+
"""Set an attribute on the EventFiringWebElement or wrapped element.
239+
240+
Sets internal attributes (those starting with '_') on this instance.
241+
Other attributes are delegated to the wrapped element. Exceptions
242+
are reported to the listener.
243+
244+
Args:
245+
item: The attribute name.
246+
value: The attribute value.
247+
248+
Raises:
249+
Exception: Any exception from the wrapped element is re-raised
250+
after being reported to the listener.
251+
"""
208252
if item.startswith("_") or not hasattr(self._webelement, item):
209253
object.__setattr__(self, item, value)
210254
else:
@@ -215,6 +259,22 @@ def __setattr__(self, item, value):
215259
raise
216260

217261
def __getattr__(self, name):
262+
"""Get an attribute from the wrapped element.
263+
264+
Wraps returned WebElement objects and callable attributes. Exceptions
265+
are reported to the listener.
266+
267+
Args:
268+
name: The attribute name.
269+
270+
Returns:
271+
The attribute value from the wrapped element, with WebElement
272+
objects wrapped and callables wrapped to report exceptions.
273+
274+
Raises:
275+
Exception: Any exception from the wrapped element is re-raised
276+
after being reported to the listener.
277+
"""
218278
def _wrap(*args, **kwargs):
219279
try:
220280
result = attrib(*args, **kwargs)

0 commit comments

Comments
 (0)