On Thu, Dec 10, 2020 at 10:57:32AM -0800, Guido van Rossum wrote: > All I have to add is that I am appalled that people actually write `from > foo import __init__`
I too would be appalled if that was what people are doing, but it isn't. Looking at the code samples in the wild: https://github.com/search?l=Python&q=%22from+.__init__+import%22&type=Code I see no examples of either of the (anti-)patterns given by Gregory in his opening post: # No examples of either of these. from package import __init__ import package.__init__ I have read through the first ten, and last five, pages of the search results and what people are doing is typically: from __init__ import name or sometimes with a wildcard import. There are also a few cases using a dot: from .__init__ import name and a few cases of attempted bilingual 2 and 3 code: try: from .__init__ import name #Python 3 except: from __init__ import name So what seems to be happening is that people have a package sub-module, say "package/run.py", and in Python 2 code they wanted to import from the main package from within run.py. I don't know if that is less appalling than what Gregory has told us, but it is different, and to my mind at least it makes it more understandable and not as weird looking. This is nothing like Gregory's characterisation of cargo cult (his term) programmers writing `import package.__init__` to import package. [...] > As for how people can check whether a package is a namespace package, there > are many other ways to check for that without attempting to import > `__init__` from it. Are these many other ways a secret? *wink* Because if somebody with the experience and knowledge of MAL doesn't know them, let alone people like me, maybe you should give us a hint what they are. -- Steve _______________________________________________ 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/6XIR2ATRU5DOSP2KPVT3XGNGAIW2LENZ/ Code of Conduct: http://python.org/psf/codeofconduct/