> On 8 Apr 2022, at 16:33, Steven D'Aprano <st...@pearwood.info> wrote: > > On Tue, Apr 05, 2022 at 02:17:00PM +1000, Chris Angelico wrote: > >> Do you ever have one module that's using statute miles and >> another that's using nautical miles, but *not both in the same >> module*? The only reason to have them namespaced to modules is to >> allow different modules to use them independently. If your application >> needs to use both statute and nautical miles in the same module (most >> likely the main module), then it's going to have an issue, and your >> proposal adds a ton of complexity (that's a real unit, by the way, I >> totally didn't make it up) for no benefit whatsoever. > > That's not the real problem. > > The real problem is that my program may: > > * import ham, which registers mile as 1609.3412 m > * import spam, which registers mile as 1609.344 m > * import cheese, which registers mile as 1609.3472 m > * import aardvark, which registers mile as 1609.3426 m > * import hovercraft, which registers mile as 1853.181 m
I’ve only scanned this thread and may have missed an explanation for this, but why must there be a global registry? Explicit imports, possibly with a new dunder protocol for literal convertors feels like a better fit to the language to me. This also avoids the problem with a global registry you mention earlier. For example: : # si_units.py: : : class MeterConvertor: : def __literal__(self, value): : … : return converted : : m = MeterConvertor() : : : # script.py: : : from si_units import m : : length = 10_m # calls m.__literal__(…) That’s assuming this has to be in the language in the first place, I don’t have a strong opinion about that because I don’t have a use case for this feature myself. Ronald — Twitter / micro.blog: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YFQ45GDSURHW37IIO5LZSUPFRK7CH62S/ Code of Conduct: http://python.org/psf/codeofconduct/