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,250 points

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,890 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 in Python by Gitika
• 33,770 points
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,780 points
+1 vote
2 answers

How to resize the image canvas to maintain a square aspect ratio

down voteacceptedUsing OpenCVYou can use resize() in OpenCV to ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,780 points
+1 vote
4 answers

How to write nested dictionaries to a CSV file

Using DictWriter there is no need in ...READ MORE

answered Oct 18, 2018 in Python by Richard William
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,207 views
0 votes
0 answers