pythonpython-3.11

My Python 3.11 did not use new error message


I'm using Python 3.10 for my daily driver because of some dependency. Now, I just download Python 3.11, install it, and successfully use environment.

(env311) PS D:\user\package> py
Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

I install it because I want to utilize the new error message pointer. But, why is this that I got?

>>> import itertools
>>> 
>>> c = itertools.counter()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'itertools' has no attribute 'counter'. Did you mean: 'count'?

It didn't produce better error message claimed at this and this like this:

Traceback (most recent call last):
  File "util.py", line 3, in <module>
    c = itertools.counter()
        ^^^^^^^^^^^^^^^^^
AttributeError: module 'itertools' has no attribute 'counter'. Did you mean: 'count'?

EDIT 1

Thanks for the answer. If by chance any of you know how to enable it on jupyter notebook or other mode, greatly appreciated. For now, I can port my notebooks to scripts.


Solution

  • You're in interactive mode. The functionality you're looking for only works when a source file is available. It doesn't work for statements typed in interactively.

    Try this:

    # in foo.py
    
    import itertools
    c = itertools.counter()
    

    And run using py foo.py,

    py foo.py
    Traceback (most recent call last):
      File "D:\user\foo.py", line 2, in <module>
        c = itertools.counter()
            ^^^^^^^^^^^^^^^^^
    AttributeError: module 'itertools' has no attribute 'counter'. Did you mean: 'count'?