Yeah, and I’ve tried this in my own packages, but it’s usually very annoying to do because you have to change files every time you want to add a type alias.
Agreed. My initial thought is to not emit a warning when accessing private attributes in modules that are in the same directory or in a subdirectory as the current module, but I feel like that will have some sharp edges (and doesn’t solve the pip-tools case).
I’ll have to think about this. Maybe we want a sys.set_private_attribute_whitelist(__name__, ["pip-tools"]) function.
That’s unfortunate to hear.
We have to make compromises and trade-offs when writing a PEP. There was so much negative feedback on the ImportError that my only options were to switch to a warning or to withdraw the proposal entirely. I care more about the runtime documentation aspect of this over the enforcement, so I went with the former.
Would it help if the PEP came with a hook that made it possible to raise an error instead? We could use an audit event, for example:
import sys
def hook(event, args):
if event == "module.access_unexported":
name = args[0]
attr = args[1]
if name == "my_module":
raise ImportError(f"{attr!r} is not exported by {name!r}")
sys.addaudithook(hook)