A lot of your arguments are great for why you probably don’t want to make your module callable from a design persepctive, but only one of them is a valid argument against the PEP itself.
modules are not callable.
They could be, even in the current version of Python.
The usual expected semantics are that there are modules, classes, functions and objects.
And that doesn’t change, and every one of these is an object. From the datamodel: “All data in a Python program is represented by objects or by relations between objects.”
The fact that this has been true doesn’t change how you introduce the major flavors of objects to people. You introduce them as separate things, and later as they learn more Python they learn that these things are all unified.
You need to be clear about which is which not just in any import statement but also in any lines of code that follow on from that import statement
You should, but you don’t need to. Python is a dynamically typed language. For better or worse from mod import * is a thing.
If I understand correctly…
Correct. I use IPython too. It’s great. I also have lots of custom macros and utilties to help with my RSI.
I also want the ability to make my modules callable, which is good because I can do that right now - with or without this PEP. We don’t need to debate if I should or not. A lot of the discussion here is losing sight of that, and I think it makes it seem like there are more arguments against this PEP than there really are.
What should be debated is: should modules get syntactic sugar to allow them to access the dunder methods that are already available to them in a roundabout way? Should modules have an conceptually ellegant way to access their internal objectness? I think the answer to this is a resounding yes. Modules should be able to define __call__ and __iter__ with the same ease that you can do with any other object, but only __call__ is in the scope of this PEP, so let’s focus on that.
The strongest argument I’ve heard against this PEP is that this will “bless” the practice of defining __call__ and cause module developers to over-use the capability. I think that will happen to some extent, but I also think it won’t happen often enough to cause real problems. There are only a few cases where it is a good idea to have a callable module. As you said: “most modules will not do this at all”.
I think this argument is entirely countered by the fact that it removes the disconnect of why a(b) doesn’t find __call__ when a is a module, but it does when a is a class-instance, even though they share the same data model.