DOC Remove incorrect getattr limitation from docs (#899)

This commit is contained in:
Hood Chatham 2020-12-21 01:08:09 -08:00 committed by GitHub
parent 9472852450
commit 9d978f0e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 25 deletions

View File

@ -85,31 +85,6 @@ to make this more complete):
| `x == y` | `x == y` |
| `x.typeof` | `typeof x` |
One important difference between Python objects and Javascript objects is that
if you access a missing member in Python, an exception is raised. In Javascript,
it returns `undefined`. Since we can't make any assumptions about whether the
Javascript member is missing or simply set to `undefined`, Python mirrors the
Javascript behavior. For example:
```javascript
// Javascript
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
point = new Point(42, 43))
```
```python
# python
from js import point
assert point.y == 43
del point.y
assert point.y is None
```
### Python from Javascript
When passing a Python object to Javascript, the Javascript [Proxy

View File

@ -1,5 +1,6 @@
# See also test_pyproxy, test_jsproxy, and test_python.
import pytest
from selenium.common.exceptions import WebDriverException
def test_python2js(selenium):
@ -240,3 +241,33 @@ def test_error_from_js(selenium):
def test_error_from_python(selenium):
selenium.run("err = Exception('hello there?');")
assert_py_to_js_to_py(selenium, "err")
def test_jsproxy_attribute_error(selenium):
selenium.run_js(
"""
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
window.point = new Point(42, 43)
"""
)
selenium.run(
"""
from js import point
assert point.y == 43
"""
)
msg = "AttributeError: z"
with pytest.raises(WebDriverException, match=msg):
selenium.run("point.z")
selenium.run("del point.y")
msg = "AttributeError: y"
with pytest.raises(WebDriverException, match=msg):
selenium.run("point.y")
assert selenium.run_js("return point.y;") is None