So this is exactly the same as `types.SimpleNamespace`, but with special syntax?!
On Sat, May 1, 2021, 7:57 PM Matt del Valle <matthew...@gmail.com> wrote: > Hi all! > > So this is a proposal for a new soft language keyword: > > namespace > > I started writing this up a few hours ago and then realized as it was > starting to get away from me that there was no way this was going to be > even remotely readable in email format, so I created a repo for it instead > and will just link to it here. The content of the post is the README.md, > which github will render for you at the following link: > > https://github.com/matthewgdv/namespace > > I'll give the TLDR form here, but I would ask that before you reply please > read the full thing first, since I don't think a few bullet-points give the > necessary context. You might end up bringing up points I've already > addressed. It will also be very hard to see the potential benefits without > seeing some actual code examples. > > TLDR: > > - In a single sentence: this proposal aims to add syntactic sugar for > setting and accessing module/class/local attributes with dots in their name > > - the syntax for the namespace keyword is similar to the simplest form of > a class definition statement (one that implicitly inherits from object), so: > > namespace some_name: > ... # code goes here > > - any name bound within the namespace block is bound in exactly the same > way it would be bound if the namespace block were not there, except that > the namespace's name and a dot are prepended to the key when being inserted > into the module/class/locals dict. > > - a namespace block leaves behind an object that serves to process > attribute lookups on it by prepending its name plus a dot to the lookup and > then delegating it to whatever object it is in scope of > (module/class/locals) > > - This would allow for small performance wins by replacing the use of > class declarations that is currently common in python for namespacing, as > well as making the writer's intent explicit > > - Crucially, it allows for namespacing the content of classes, by grouping > together related methods. This improves code clarity and is useful for > library authors who design their libraries with IDE autocompletion in mind. > This cannot currently be done by nesting classes. > > I live in the UK so I'm going to bed now (after working on this for like > the last 6 hours). I'll be alive again in maybe 8 hours or so and will be > able to reply to any posts here then. > > Cheers everyone :) > _______________________________________________ > 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/7DAX2JTKZKLRT4CKKBRACNBJLHQUCN6E/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/SFXURMEILWU2BALQZ7RL7ESZLMHS2GFO/ Code of Conduct: http://python.org/psf/codeofconduct/