Skip to content

Commit 6b50b0b

Browse files
authored
Docs Fix cross references to abort signal and abort controller [skip ci] (pyodide#5275)
1 parent 555ccf2 commit 6b50b0b

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

docs/conf.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
def ignore_typevars():
2828
"""These are all intentionally broken. Disable the warnings about it."""
29-
PY_TYPEVARS_TO_IGNORE = ("T", "T_co", "T_contra", "V_co", "KT", "VT", "VT_co")
29+
PY_TYPEVARS_TO_IGNORE = ("T", "T_co", "T_contra", "V_co", "KT", "VT", "VT_co", "P")
3030
JS_TYPEVARS_TO_IGNORE = ("TResult", "TResult1", "TResult2", "U")
3131

3232
nitpick_ignore.extend(
@@ -350,6 +350,7 @@ def typehints_formatter(annotation, config):
350350
module = get_annotation_module(annotation)
351351
class_name = get_annotation_class_name(annotation, module)
352352
except ValueError:
353+
assert annotation == Ellipsis
353354
return None
354355
full_name = f"{module}.{class_name}"
355356
if full_name == "typing.TypeVar":
@@ -358,6 +359,11 @@ def typehints_formatter(annotation, config):
358359
return f"``{annotation.__name__}``"
359360
if full_name == "ast.Module":
360361
return "`Module <https://docs.python.org/3/library/ast.html#module-ast>`_"
362+
# TODO: perhaps a more consistent way to handle JS xrefs / type annotations?
363+
if full_name == "pyodide.http.AbortController":
364+
return ":js:class:`AbortController`"
365+
if full_name == "pyodide.http.AbortSignal":
366+
return ":js:class:`AbortSignal`"
361367
return None
362368

363369

docs/sphinx_pyodide/sphinx_pyodide/mdn_xrefs.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"showDirectoryPicker": "API/Window/",
1818
},
1919
"js:class": {
20+
"AbortController": "API/",
21+
"AbortSignal": "API/",
2022
"Array": "$global/",
2123
"NodeList": "API/",
2224
"XMLHttpRequest": "API/",
@@ -41,6 +43,7 @@
4143
"Float32Array": "$global/",
4244
"Float64Array": "$global/",
4345
"Map": "$global/",
46+
"Response": "API/",
4447
"Set": "$global/",
4548
# the JavaScript domain has no exception type for some reason...
4649
"Error": "$global/",

src/py/_pyodide/_core_docs.py

+14
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,12 @@ def aclose(self) -> Awaitable[None]:
893893

894894

895895
class JsCallable(JsProxy, Generic[P, T]):
896+
"""A JavaScript callable
897+
898+
A JavaScript object is treated as a callable if `typeof x` returns
899+
`"function"`.
900+
"""
901+
896902
_js_type_flags = ["IS_CALLABLE"]
897903

898904
__call__: Callable[P, T]
@@ -1175,6 +1181,13 @@ def __delitem__(self, idx: KT) -> None:
11751181

11761182

11771183
class JsOnceCallable(JsCallable[P, T], Generic[P, T]):
1184+
"""A JavaScript handle for a Python function which can be called at most
1185+
once.
1186+
1187+
After it is called, the reference to the underlying Python object is
1188+
released and attempting to call it again will raise an `Error`.
1189+
"""
1190+
11781191
def destroy(self):
11791192
pass
11801193

@@ -1603,6 +1616,7 @@ def can_run_sync() -> bool:
16031616
"JsProxy",
16041617
"JsDomElement",
16051618
"JsCallable",
1619+
"JsOnceCallable",
16061620
"JsTypedArray",
16071621
"run_sync",
16081622
"can_run_sync",

src/py/pyodide/ffi/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"JsIterator",
4747
"JsMap",
4848
"JsMutableMap",
49+
"JsOnceCallable",
4950
"JsPromise",
5051
"JsProxy",
5152
"JsDomElement",

src/py/pyodide/http.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,43 @@
1919
from js import XMLHttpRequest
2020
except ImportError:
2121
pass
22+
else:
23+
# Hack for documentation xrefs, we replace these with links to mdn in the
24+
# sphinx conf.py. TODO: Maybe come up with some better / more systematic way
25+
# to handle this situation.
26+
class AbortController: # type:ignore[no-redef]
27+
pass
28+
29+
class AbortSignal: # type:ignore[no-redef]
30+
pass
31+
2232

2333
__all__ = [
2434
"open_url",
2535
"pyfetch",
2636
"FetchResponse",
37+
"HttpStatusError",
38+
"BodyUsedError",
39+
"AbortError",
2740
]
2841

2942

3043
class HttpStatusError(OSError):
44+
"""A subclass of :py:exc:`OSError` raised by :py:meth:`FetchResponse.raise_for_status`
45+
if the response status is 4XX or 5XX.
46+
47+
Parameters
48+
----------
49+
status :
50+
The http status code of the request
51+
52+
status_text :
53+
The http status text of the request
54+
55+
url :
56+
The url that was requested
57+
"""
58+
3159
status: int
3260
status_text: str
3361
url: str
@@ -135,9 +163,13 @@ class FetchResponse:
135163
Parameters
136164
----------
137165
url
138-
URL to fetch
166+
URL that was fetched
139167
js_response
140-
A :py:class:`~pyodide.ffi.JsProxy` of the fetch response
168+
A :py:class:`~pyodide.ffi.JsProxy` of the fetch :js:class:`Response`.
169+
abort_controller
170+
The abort controller that may be used to cancel the fetch request.
171+
abort_signal
172+
The abort signal that was used for the fetch request.
141173
"""
142174

143175
def __init__(
@@ -223,7 +255,7 @@ def _raise_if_failed(self) -> None:
223255
raise BodyUsedError
224256

225257
def raise_for_status(self) -> None:
226-
"""Raise an :py:exc:`HttpStatusError` if the status of the response is an error (4xx or 5xx)"""
258+
"""Raise an :py:exc:`~pyodide.http.HttpStatusError` if the status of the response is an error (4xx or 5xx)"""
227259
if 400 <= self.status < 600:
228260
raise HttpStatusError(self.status, self.status_text, self.url)
229261

0 commit comments

Comments
 (0)