On 6/24/21 7:09 AM, Simão Afonso wrote: > On 2021-06-24 20:59:31, Steven D'Aprano wrote: >> Seriously, there's a time to realise when arguments against a feature >> devolve down to utterly spurious claims that Python programmers are >> idiots who will be confused by: >> >> from extensions use flatten >> mylist.flatten() >> >> but can instantly understand: >> >> from extensions import flatten >> flatten(mylist) > Does this mean importing a module can modify other objects, including > builtins? Should this spooky-action-at-a-distance be encouraged? > > OTOH, this already happens in the stdlib with rlcompleter, I assume > using monkey-patching. This is a special case for interactive use, > though. > > https://docs.python.org/3/library/rlcompleter.html
Yes, importing a module runs the global code in that module, and that code can not only define the various things in that module but can also manipulate the contents of other modules. This doesn't mean that spooky-action-at-a-distance is always good, but sometimes it is what is needed. You need to be aware of the power that you wield. -- Richard Damon _______________________________________________ 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/I555D55DJBOV4V3MTZ2IJQ3MIDDOHQKV/ Code of Conduct: http://python.org/psf/codeofconduct/