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
_______________________________________________ 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/5NHD4LS4NGTXNM5RDKCCSBXQPURBTC4Q/ Code of Conduct: http://python.org/psf/codeofconduct/