numerary icon indicating copy to clipboard operation
numerary copied to clipboard

Feature proposal: Expose CachingProtocolMeta

Open antonagestam opened this issue 3 years ago • 4 comments

Hi posita 👋

I'm about to start using CachingProtocolMeta in phantom-types, to define narrower parameter types for comparison et cetera. Would you be willing to consider a PR that exposes (with __all__) and documents CachingProtocolMeta?

antonagestam avatar Jul 06 '22 12:07 antonagestam

Meaning so that you can do this …

from numerary import CachingProtocolMeta

… instead of this …

from numerary.types import CachingProtocolMeta

… ?

posita avatar Jul 06 '22 22:07 posita

@posita I actually meant so that I can do:

from numerary.types import CachingProtocolMeta

... without a type error. Because that name isn't in __all__, mypy rightfully considers it private, see the ignore comment here for reference: https://github.com/antonagestam/phantom-types/blob/599db5affb249b691e6dd79bfb7a25af00888579/src/phantom/_utils/types.py#L3.

The specific import path isn't important to me 🙂

antonagestam avatar Jul 06 '22 22:07 antonagestam

Ah! Brilliant! My guess is that this stems from the fact that it's defined in _protocol (note the underscore prefix). One option is to rename numerary._protocol to numerary.protocol and then one could do …

from numerary.protocol import CachingProtocolMeta

Yet another option is to move CachingProtocolMeta into numerary.types and delete _protocol.py altogether. I'm not particularly opinionated either way. Feel free to go with whatever aesthetic brings you the most joy. In addition to refactoring any code, I think the only other spot to change would be where and how it appears in the docs.

posita avatar Jul 06 '22 22:07 posita

Cool, great knowing there's a way forward here. I'm on vacation now but might be able to find time addressing this later this summer. Thanks for the feedback! 🙏

antonagestam avatar Jul 08 '22 03:07 antonagestam