Skip to content

feat: suppress open client warnings in SPARQLWrapper.queries#127

Merged
lu-pl merged 2 commits into
mainfrom
lupl/suppress-client-warning-queries
Feb 9, 2026
Merged

feat: suppress open client warnings in SPARQLWrapper.queries#127
lu-pl merged 2 commits into
mainfrom
lupl/suppress-client-warning-queries

Conversation

@lu-pl
Copy link
Copy Markdown
Owner

@lu-pl lu-pl commented Feb 4, 2026

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
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.

@lu-pl lu-pl force-pushed the lupl/suppress-client-warning-queries branch 2 times, most recently from 4833ba4 to 2a1ce8b Compare February 4, 2026 12:06
@lu-pl lu-pl marked this pull request as draft February 7, 2026 08:35
lu-pl added 2 commits February 9, 2026 08:00
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.
@lu-pl lu-pl force-pushed the lupl/suppress-client-warning-queries branch from 2a1ce8b to 5d507b1 Compare February 9, 2026 07:10
@lu-pl lu-pl marked this pull request as ready for review February 9, 2026 07:12
@lu-pl lu-pl merged commit a402fe9 into main Feb 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possibly suppress warnings about open client in SPARQLWrapper.queries

1 participant