On Mon, Apr 11, 2022 at 12:22 PM Chris Angelico <ros...@gmail.com> wrote:
> > as oped what I understand was being proposed via a "global registry", > which is that code: > > > > distance = 500[miles] > > > > would work even if there were no name "miles" in that namespace(s) -- > and it would, instead go look for it in the global registry -- which could > have been manipulated by the application to mean nautical miles, or statute > miles, or whatever. > > > > And THAT I think is a bad idea. > > It's a good thing we don't have a mutable builtins module, then. Oh right. > :) > Python is a highly dynamic, you can monkey patch the heck out of almost anything -- you surely don't think is a good programming practice to alter the behavior of builtins at the "program" level ? > > > use my_units_system's definition of miles in that module without having > explicitly imported the name. > > > > The trouble is, you now force everyone to do bulk imports - almost > certainly star imports. How are you going to populate the namespace > appropriately if not with a star import? What happens if you don't > want the entire contents of the module? > 1) if you really want really easy to write units, then user, use star imports. But most code is going to use what, a half a dozen (or less) units? is it so bad to write: from my_unit_system import miles, ft, kg, lbs, gallons or: import my_unit_sytem as U and go from there -- frankly, it's how most of PYthon already works. If you want a quick and easy uit-aware calculator -- then write an application or pre-processor for the code. > Having a registry means you can get finer granularity with > registration functions, without a massively complex module and > submodule system, or heaps of manual imports. > if there were a way to use a module level registry that sure -- I'm not sure that's possible or easy, but please don't make it global so that when I write code in a library, I have no idea what context I'll be working in. But honestly, I don't think I like the idea -- but no one has actually fleshed out exactly how it would work -- so maybe I would like the actual proposal -- who knows? But I would hope that if anyone does come up with a proposal, they will address the core issue I'm harping on here: when I write code that may be run in the context of someone else's "application" (or my own, two years later :-) ) -- I want to know exactly what the unit calculations will mean, and that they won't be messed with at run time by a standard recommended practice. -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/6GDVZ3NXYAF75EO7OWMIHOMKDXQDVWEZ/ Code of Conduct: http://python.org/psf/codeofconduct/