Skip to content

Commit

Permalink
sniffio is now used differently (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia authored Apr 13, 2024
1 parent 97fe48d commit cd07501
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 67 deletions.
6 changes: 3 additions & 3 deletions docs/source/quickstart/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Example where the ``cbor`` and ``msgpack`` extensions are installed:
(.venv) $ pip install "easynetwork[cbor,msgpack]"
.. seealso::
.. todo::

:doc:`/api/lowlevel/async/backend`
See how ``sniffio`` is used.
Explain what we do with ``sniffio`` when adding documentation of ``AsyncIOBackend``
(because it is *NOT* for ``sniffio.current_async_library()``).
19 changes: 1 addition & 18 deletions src/easynetwork/lowlevel/api_async/backend/_sniffio_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,18 @@

from __future__ import annotations

__all__ = ["current_async_library", "setup_sniffio_contextvar"]
__all__ = ["setup_sniffio_contextvar"]

import contextvars
import sys


def _current_async_library_fallback() -> str:
if "asyncio" in sys.modules:
import asyncio

try:
asyncio.get_running_loop()
except RuntimeError:
pass
else:
return "asyncio"
raise RuntimeError("unknown async library, or not in async context")


try:
import sniffio
except ModuleNotFoundError:
current_async_library = _current_async_library_fallback

def setup_sniffio_contextvar(context: contextvars.Context, library_name: str | None, /) -> None:
pass

else:
current_async_library = sniffio.current_async_library

def setup_sniffio_contextvar(context: contextvars.Context, library_name: str | None, /) -> None:
context.run(sniffio.current_async_library_cvar.set, library_name)

This file was deleted.

0 comments on commit cd07501

Please sign in to comment.