On 5/04/22 4:17 pm, Chris Angelico wrote:
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,

If there's a single global registry, and they both register the
unit under the same name, then there will be problems if both
modules are imported by the same program, even if the two units
are never used together in the same module.

What's your proposal?

I'm not sure, but we really need to avoid having a global
registry.

Treating units as ordinary names looked up as usual would
be the simplest thing to do.

If you really want units to be in a separate namespace,
I think it would have to be per-module, with some variant
of the import statement for getting things into it.

    from units.si import units *
    from units.imperial import units inch, ft, mile
    from units.nautical import units mile as nm

It's more like using decimal.getcontext() and making
changes. That's global.

Personally I think giving Decimal a global context was a mistake,
so arguing that "it's no worse than Decimal" isn't going to do much
to convince me. :-)

But in any case, a Decimal context and the proposed global unit
registry are very different things. Just because one doesn't seem
to cause problems doesn't mean the other won't either.

--
Greg

_______________________________________________
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/TOD2KJLONTUHRGNITAFVGQD3QSLDIJBS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to