Hello all, In Python 3.10 and 3.11, exception tracebacks are being greatly improved. I noticed that there's nothing related to a fairly common (in my personal experience) cryptic traceback relating to the `with` statement:
with ContextManager as ctx: ... # do something with `ctx` ... Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: __enter__
This occurs when one forgets to use a instance of a context manager class and uses the class itself. It's obviously not a very helpful traceback. ("Is it not a context manager?" "Is it the wrong class?") Something like the following would be better.
with ContextManager as ctx: ... # do something with `ctx` ... Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: <type Context manager> is not a context manager. Did you mean "with ContextManager()..."?
The actual traceback message should probably be more specific than "<type Context manager> is not a context manager". Thoughts? -- Finn