This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add a feature similar to C++ "using some_namespace"
Type: enhancement Stage: resolved
Components: Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, turion
Priority: normal Keywords:

Created on 2011-02-07 19:25 by turion, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg128153 - (view) Author: Manuel Bärenz (turion) Date: 2011-02-07 19:25
In C++, the the approach to the namespace problem is having different namespaces that should not contain different definitions of the same name.
Members of a namespace can be accessed explicitly by e.g. calling "std::cout << etc." or "using namespace std; cout << etc."

I understand Pythons approach to be "objects can be used as namespaces and their attributes are the names they contain". I find this a very beautiful way of solving the issue, but it has a downside, in my opinion, because it lacks the "using" directive from C++.

If the object is a module, we can of course do "from mymodule import spam, eggs". But if it is not a module, this does not work.

Consider for example:

class Spam(object):
    def frobnicate(self):
        self.eggs = self.buy_eggs()
        self.scrambled = self.scramble(self.eggs)
        return self.scrambled > 42

This could be easier to implement and read if we had something like:

class Spam(object):
    def frobnicate(self):
        using self:
            eggs = buy_eggs()
            scrambled = scramble(eggs)
            return scrambled > 42

Of course this opens a lot of conceptual questions like how should this using block behave if self doesn't have an attribute called "eggs", but I think it is worth considering.
msg128154 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-02-07 19:33
This is a topic more suited to python-ideas.  It isn't likely to get much traction there, but you can try :)
History
Date User Action Args
2022-04-11 14:57:12adminsetgithub: 55355
2011-02-07 19:33:46r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg128154

resolution: rejected
stage: resolved
2011-02-07 19:25:05turioncreate