![](https://secure.gravatar.com/avatar/9b513ee7cc400c9b7374f4697a1e69ad.jpg?s=120&d=mm&r=g)
On Sat, Aug 18, 2018 at 2:13 PM, Nathaniel Smith <njs@pobox.com> wrote:
On Sat, Aug 18, 2018, 01:22 Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
Also, just to be clear, I think the idea of a library to sniff this information is great.
It's just the location of where this information is being stored that I'm focusing in on and asking about. It seems like it should be in a "neutral" location, and in particular different from / decoupled from the library above.
One advantage of decoupling the sniffing library from the registry location is that it would allow for someone to write an improved library in the future (say "detectio") without forever locking in / requiring the old library to be installed.
Yeah, we discussed this some when initially designing it, because we were worried about the lock in issue too. Obviously if you want to do anything you need to make some decisions, but to reduce the risk here we intentionally kept sniffio as minimal and unopinionated as possible: https://github.com/python-trio/sniffio/issues/1#issuecomment-408812146
Have you seen the code? It's not *entirely* trivial – certainly big enough to contain a bug or two – but it's tiny and only contains what it absolutely needs to work: a contextvar (native on 3.7, or via Yury's backport library on earlier pythons), and a fallback for detecting asyncio (since as a stdlib module it can't really work any other way).
https://github.com/python-trio/sniffio/blob/master/sniffio/_impl.py
Yes, I had looked at the code a few times and agree it's simple and useful. (But it could always grow.) I looked in the linked issue and didn't see any discussion of the registry location though, which is the part I was interested in. The kind of alternative I had in mind for a neutral location is setting an attribute with an agreed upon name on a module in the standard lib, perhaps something like `contextvars.current_async_library_cvar` to use your naming. This is analogous to agreeing on a file name to store information of a certain kind in a repository root, like .travis.yml, package.json, or pyproject.toml. It's light-weight and doesn't require any infrastructure or tying to a particular package on PyPI. --Chris