Commit e09b80c
committed
feat: suppress open client warnings in SPARQLWrapper.queries
The `SPARQLWrapper.queries` method is a sync wrapper around async code
and intended to be a convenience method for users wishing to execute
multiple operations concurrently but do not want to write async code themselves.
`SPARQLWrapper.queries` internally creates a `SPARQLWrapper` instance
with a shared `httpx.AsyncClient` that is then used in an async
context manger for calls to `SPARQLWrapper.aquery`.
> `SPARQLWrapper.queries` ergo is a managed application of
`SPARQLWrapper.aquery` that uses the context manager API of
`SPARQLWrapper` internally.
This application causes the sparqlx `ClientManager` to emit a warning
about an open client though. While this is technically correct and
intended behavior, it is superfluos and potentially misleading for
`SPARQLWrapper.queries` which actually manages the client through the
context manager.
It is therefore preferable to suppress client warnings for
`SPARQLWrapper.queries`.
The change uses a PEP-806-inspired async wrapper around the sync
`warnings.catch_warnings` context manager to suppress `Userwarnings`
coming from `sparqlx.utils.client_manager` within
`SPARQLWrapper.queries`.
Note: `warnings.catch_warnings` is not concurrency-safe, see
[Concurrent safety of Context
Managers](https://docs.python.org/3/library/warnings.html#concurrent-safety-of-context-managers)
in the `warnings` docs. Although the implemented change uses a
`contextlib.contextmanager` which closures context state and can ergo mitigate concurrency-safety
problems, `warnings` filters are global and would actually need
explicit locking or protection from a `ContextVar`. In the case at hand,
this is of no concern however, since `SPARQLWrapper.queries` controls
its own encapsulated event loop.
Closes #124.1 parent 0edc822 commit e09b80c
2 files changed
Lines changed: 38 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
486 | 492 | | |
487 | 493 | | |
488 | 494 | | |
489 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
490 | 510 | | |
491 | 511 | | |
492 | 512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
6 | | - | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
0 commit comments