Re-assigning a name to itself

0 votes
In the following lines of multiprocessing package of standard libraries:

dict = dict
list = list
 

What's the point of rebinding some names already available on __builtins__ into the module scope? What is it trying to achieve? I couldn't find a suitable and relevant explanation.
Oct 17, 2018 in Python by SDeb
• 13,300 points
142 views

1 answer to this question.

0 votes
This code occurs in multiprocessing.dummy, a "fake" version of multiprocessing that implements the functionality with threads. If you look down a few lines, you'll see

def Manager():
    return sys.modules[__name__]
multiprocessing.dummy implements Manager as a function that just returns the multiprocessing.dummy module itself, so the multiprocessing.dummy module object has to provide the API of a multiprocessing Manager object. The lines

dict = dict
list = list
copy the bindings for the dict and list names from the builtins namespace into the module's namespace, so you can do

m = multiprocessing.dummy.Manager()
d = m.dict()
as if you had a real multiprocessing.Manager()
answered Oct 17, 2018 by ana1504.k
• 7,910 points

Related Questions In Python

0 votes
1 answer

How to a write reg expression that confirms an email id using the python reg expression module “re”?

Hey, @Roshni, Python has a regular expression module ...READ MORE

answered Jun 26, 2020 in Python by Gitika
• 65,950 points
217 views
0 votes
1 answer
0 votes
1 answer

How to import a module given its name as string?

With Python older than 2.7/3.1, that's pretty ...READ MORE

answered Nov 25, 2020 in Python by Gitika
• 65,950 points
124 views
0 votes
1 answer

How to invoke a function on an object dynamically by name?

Use "getattr":  obj = MyClass() try: ...READ MORE

answered Dec 3, 2020 in Python by Gitika
• 65,950 points
665 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,402 views
0 votes
0 answers