Friendly tracebacks - in English

Friendly-traceback aims to provide friendlier feedback when an exception is raised than what is done by Python. Below, we can find some examples. SyntaxError cases, as well as TabError and IndentationError cases, are shown in a separate page. Ideally, an example of each case handled by friendly-traceback should be included here.

Note

The content of this page is generated by running trb_english.py located in the tests/ directory. This needs to be done explicitly, independently of updating the documentation using Sphinx.

Friendly version: 0.3 Python version: 3.8.4

ArithmeticError

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_arithmetic_error.py", line 9, in test_Generic
    raise ArithmeticError('error')
ArithmeticError: error

`ArithmeticError` is the base class for those built-in exceptions
that are raised for various arithmetic errors.
It is unusual that you are seeing this exception;
normally, a more specific exception should have been raised.

Exception raised on line 9 of file TESTS:\runtime\test_arithmetic_error.py.

    7:         # Usually, a subclass such as ZeroDivisionError, etc., would
    8:         # likely be raised.
--> 9:         raise ArithmeticError('error')
   10:     except ArithmeticError as e:

        ArithmeticError: <class ArithmeticError>

AttributeError

Attribute from other module

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 270, in test_Attribute_from_other_module
    keyword.pi
AttributeError: module 'keyword' has no attribute 'pi'

    Did you mean one of the following modules: `math, cmath`?
An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

Instead of the module `keyword`, perhaps you wanted to use
the attribute `pi` of one of the following modules:
`math, cmath`.

Exception raised on line 270 of file TESTS:\runtime\test_attribute_error.py.

   268:     import cmath
   269:     try:
-->270:         keyword.pi
   271:     except AttributeError as e:

        keyword: <module keyword> from PYTHON_LIB:\keyword.py

Builtin function

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 188, in test_Builtin_function
    len.text
AttributeError: 'builtin_function_or_method' object has no attribute 'text'

    Did you mean `len(text)`?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

`len` is a function. Perhaps you meant to write
`len(text)`

Exception raised on line 188 of file TESTS:\runtime\test_attribute_error.py.

   186:     text = 'Hello world!'
   187:     try:
-->188:         len.text
   189:     except AttributeError as e:

        text: 'Hello world!'
        len: <builtin function len>

Builtin module with no file

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 205, in test_Builtin_module_with_no_file
    sys.foo
AttributeError: module 'sys' has no attribute 'foo'

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

Python tells us that no object with name `foo` is
found in module `sys`.

Exception raised on line 205 of file TESTS:\runtime\test_attribute_error.py.

   203:
   204:     try:
-->205:         sys.foo
   206:     except AttributeError as e:

        sys: <module sys (builtin)>

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 36, in test_Generic
    a.x  # Testing instance
AttributeError: 'A' object has no attribute 'x'

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

The object `a` has no attribute named `x`.

Exception raised on line 36 of file TESTS:\runtime\test_attribute_error.py.

   34:     try:
   35:         a = A()
-->36:         a.x  # Testing instance
   37:     except AttributeError as e:

        a: <A object> from test_attribute_error.test_Generic

Module attribute typo

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 113, in test_Module_attribute_typo
    math.cost
AttributeError: module 'math' has no attribute 'cost'

    Did you mean `cos`?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

Instead of writing `math.cost`, perhaps you meant to write one of
the following names which are attributes of module `math`:
`cos, cosh, acos`

Exception raised on line 113 of file TESTS:\runtime\test_attribute_error.py.

   111:
   112:     try:
-->113:         math.cost
   114:     except AttributeError as e:

        math: <module math (builtin)>

Nonetype

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 152, in test_Nonetype
    a.b
AttributeError: 'NoneType' object has no attribute 'b'

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

You are attempting to access the attribute `b`
for a variable whose value is `None`.
Exception raised on line 152 of file TESTS:\runtime\test_attribute_error.py.

   150:     a = None
   151:     try:
-->152:         a.b
   153:     except AttributeError as e:

        a: None

Object attribute typo

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 52, in test_Object_attribute_typo
    a.appendh(4)
AttributeError: 'list' object has no attribute 'appendh'

    Did you mean `append`?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

Perhaps you meant to write `a.append` instead of `a.appendh`

Exception raised on line 52 of file TESTS:\runtime\test_attribute_error.py.

   50:     try:
   51:         a = [1, 2, 3]
-->52:         a.appendh(4)
               ^^^^^^^^^
   53:     except AttributeError as e:

        a: [1, 2, 3]

Perhaps comma

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 171, in test_Perhaps_comma
    a = [abcd
AttributeError: 'str' object has no attribute 'defg'

    Did you mean to separate object names by a comma?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

`defg` is not an attribute of `abcd`.
However, both `abcd` and `defg` are known objects.
Perhaps you wrote a period to separate these two objects,
instead of using a comma.

Exception raised on line 171 of file TESTS:\runtime\test_attribute_error.py.

   169:     # fmt: off
   170:     try:
-->171:         a = [abcd
   172:         .defg]

        abcd: 'hello'
        defg: 'world'

Shadow stdlib module

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 134, in test_Shadow_stdlib_module
    turtle.Pen
AttributeError: module 'turtle' has no attribute 'Pen'

    Did you give your program the same name as a Python module?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

You imported a module named `turtle` from `TESTS:\turtle.py`.
There is also a module named `turtle` in Python's standard library.
Perhaps you need to rename your module.

Exception raised on line 134 of file TESTS:\runtime\test_attribute_error.py.

   132:
   133:     try:
-->134:         turtle.Pen
   135:     except AttributeError as e:

        turtle: <module turtle> from TESTS:\turtle.py

Tuple by accident

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 240, in test_Tuple_by_accident
    something.upper()
AttributeError: 'tuple' object has no attribute 'upper'

    Did you write a comma by mistake?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

`something` is a tuple that contains a single item
which does have `'upper'` as an attribute.
Perhaps you added a trailing comma by mistake at the end of the line
where you defined `something`.

Exception raised on line 240 of file TESTS:\runtime\test_attribute_error.py.

   238:     something = "abc",  # note trailing comma
   239:     try:
-->240:         something.upper()
                ^^^^^^^^^^^^^^^
   241:     except AttributeError as e:

        something: ('abc',)

Use builtin

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 68, in test_Use_builtin
    a.length()
AttributeError: 'list' object has no attribute 'length'

    Did you mean `len(a)`?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

The object `a` has no attribute named `length`.
Perhaps you can use the Python builtin function `len` instead:
`len(a)`.
Exception raised on line 68 of file TESTS:\runtime\test_attribute_error.py.

   66:     try:
   67:         a = [1, 2, 3]
-->68:         a.length()
               ^^^^^^^^
   69:     except AttributeError as e:

        a: [1, 2, 3]

Use synonym

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 84, in test_Use_synonym
    a.add(4)
AttributeError: 'list' object has no attribute 'add'

    Did you mean `append`?

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

The object `a` has no attribute named `add`.
However, `a` has the following attributes with similar meanings:
`append, extend, insert`.

Exception raised on line 84 of file TESTS:\runtime\test_attribute_error.py.

   82:     try:
   83:         a = [1, 2, 3]
-->84:         a.add(4)
               ^^^^^
   85:     except AttributeError as e:

        a: [1, 2, 3]

Using slots

Traceback (most recent call last):
  File "TESTS:\runtime\test_attribute_error.py", line 225, in test_Using_slots
    f.b = 1
AttributeError: 'F' object has no attribute 'b'

An `AttributeError` occurs when the code contains something like
    `object.x`
and `x` is not a method or attribute (variable) belonging to `object`.

The object `f` has no attribute named `b`.
Note that object `f` uses `__slots__` which prevents
the creation of new attributes.
The following are some of its known attributes:
`a`.
Exception raised on line 225 of file TESTS:\runtime\test_attribute_error.py.

   223:     f = F()
   224:     try:
-->225:         f.b = 1
   226:     except AttributeError as e:

        f: <F object> from test_attribute_error.test_Using_slots

FileNotFoundError

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_file_not_found_error.py", line 6, in test_Generic
    open("does_not_exist")
FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist'

A `FileNotFoundError` exception indicates that you
are trying to open a file that cannot be found by Python.
This could be because you misspelled the name of the file.

In your program, the name of the
file that cannot be found is `does_not_exist`.

Exception raised on line 6 of file TESTS:\runtime\test_file_not_found_error.py.

   4: def test_Generic():
   5:     try:
-->6:         open("does_not_exist")
   7:     except FileNotFoundError as e:

        open: <builtin function open>

ImportError

Circular import

Traceback (most recent call last):
  File "TESTS:\runtime\test_import_error.py", line 20, in test_Circular_import
    import circular_a
  File "TESTS:\circular_a.py", line 2, in <module>
    import circular_b
  File "TESTS:\circular_b.py", line 2, in <module>
    from circular_a import a
ImportError: cannot import name 'a' from partially initialized module 'circular_a' (most likely due to a circular import) (C:\Users\andre\github\friendly\tests\circular_a.py)

An `ImportError` exception indicates that a certain object could not
be imported from a module or package. Most often, this is
because the name of the object is not spelled correctly.

The object that could not be imported is `a`.
The module or package where it was
expected to be found is `circular_a`.

The problem was likely caused by what is known as a 'circular import'.
First, Python imported and started executing the code in file
   'TESTS:\runtime\test_import_error.py'.
which imports module `circular_a`.
During this process, the code in another file,
   'TESTS:\circular_b.py'
was executed. However in this last file, an attempt was made
to import the original module `circular_a`
a second time, before Python had completed the first import.

Execution stopped on line 20 of file TESTS:\runtime\test_import_error.py.

   18: def test_Circular_import():
   19:     try:
-->20:         import circular_a
   21:     except ImportError as e:

Exception raised on line 2 of file TESTS:\circular_b.py.

   1: """File used in for test_circular_import() in test_import_error.py"""
-->2: from circular_a import a

Simple import error

Traceback (most recent call last):
  File "TESTS:\runtime\test_import_error.py", line 6, in test_Simple_import_error
    from math import Pi
ImportError: cannot import name 'Pi' from 'math' (unknown location)

    Did you mean `pi`?

An `ImportError` exception indicates that a certain object could not
be imported from a module or package. Most often, this is
because the name of the object is not spelled correctly.

Perhaps you meant to import `pi` (from `math`) instead of `Pi`

Exception raised on line 6 of file TESTS:\runtime\test_import_error.py.

   4: def test_Simple_import_error():
   5:     try:
-->6:         from math import Pi
   7:     except ImportError as e:

IndexError

Long list

Traceback (most recent call last):
  File "TESTS:\runtime\test_index_error.py", line 24, in test_Long_list
    print(a[50], b[0])
IndexError: list index out of range

An `IndexError` occurs when you are try to get an item from a list,
a tuple, or a similar object (sequence), by using an index which
does not exists; typically, this is because the index you give
is greater than the length of the sequence.

You have tried to get the item with index `50` of `a`,
a `list` of length `40`.

Exception raised on line 24 of file TESTS:\runtime\test_index_error.py.

   22:     b = tuple(range(50))
   23:     try:
-->24:         print(a[50], b[0])
                     ^^^^^
   25:     except IndexError as e:

        a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ...]
            len(a): 40

Short tuple

Traceback (most recent call last):
  File "TESTS:\runtime\test_index_error.py", line 8, in test_Short_tuple
    print(a[3], b[2])
IndexError: tuple index out of range

    Remember: the first item of a `tuple` is at index 0.

An `IndexError` occurs when you are try to get an item from a list,
a tuple, or a similar object (sequence), by using an index which
does not exists; typically, this is because the index you give
is greater than the length of the sequence.

You have tried to get the item with index `3` of `a`,
a `tuple` of length `3`.
The largest valid index of `a` is `2`.

Exception raised on line 8 of file TESTS:\runtime\test_index_error.py.

    6:     b = [1, 2, 3]
    7:     try:
--> 8:         print(a[3], b[2])
                     ^^^^
    9:     except IndexError as e:

        a: (1, 2, 3)

KeyError

ChainMap

Traceback (most recent call last):
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\collections\__init__.py", line 965, in pop
    return self.maps[0].pop(key, *args)
KeyError: 42

    During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "TESTS:\runtime\test_key_error.py", line 23, in test_ChainMap
    d.pop(42)
  File "PYTHON_LIB:\collections\__init__.py", line 967, in pop
    raise KeyError('Key not found in the first mapping: {!r}'.format(key))
KeyError: 'Key not found in the first mapping: 42'

A `KeyError` is raised when a value is not found as a
key in a Python dict.

In your program, the key that cannot be found is `42`.

Execution stopped on line 23 of file TESTS:\runtime\test_key_error.py.

   21:     d = ChainMap({}, {})
   22:     try:
-->23:         d.pop(42)
   24:     except KeyError as e:

        d: ChainMap({}, {})
        d.pop: <bound method ChainMap.pop of ChainMap({}, {})>

Exception raised on line 967 of file PYTHON_LIB:\collections\__init__.py.

   965:             return self.maps[0].pop(key, *args)
   966:         except KeyError:
-->967:             raise KeyError('Key not found in the first mapping: {!r}'.format(key))

        key: 42
        KeyError: <class KeyError>
        format: <builtin function format>
        'Key not found in the first mapping: {!r}'.format: <builtin method format of str object>

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_key_error.py", line 7, in test_Generic
    d["c"]
KeyError: 'c'

A `KeyError` is raised when a value is not found as a
key in a Python dict.

In your program, the key that cannot be found is `c`.

Exception raised on line 7 of file TESTS:\runtime\test_key_error.py.

   5:     d = {"a": 1, "b": 2}
   6:     try:
-->7:         d["c"]
   8:     except KeyError as e:

        d: {'a': 1, 'b': 2}

LookupError

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_lookup_error.py", line 10, in test_Generic
    raise LookupError("Fake message")
LookupError: Fake message

`LookupError` is the base class for the exceptions that are raised
when a key or index used on a mapping or sequence is invalid.
It can also be raised directly by codecs.lookup().

Exception raised on line 10 of file TESTS:\runtime\test_lookup_error.py.

    8:         # other than possibly codecs.lookup(), which is why we raise
    9:         # it directly here for our example.
-->10:         raise LookupError("Fake message")
   11:     except LookupError as e:

        LookupError: <class LookupError>

ModuleNotFoundError

Not a package

Traceback (most recent call last):
  File "TESTS:\runtime\test_module_not_found_error.py", line 41, in test_Not_a_package
    import os.pathh
ModuleNotFoundError: No module named 'os.pathh'; 'os' is not a package

    Did you mean `import os.path`?

A `ModuleNotFoundError` exception indicates that you
are trying to import a module that cannot be found by Python.
This could be because you misspelled the name of the module
or because it is not installed on your computer.

Perhaps you meant `import os.path`.
`path` is a name similar to `pathh` and is a module that
can be imported from `os`.
Other objects with similar names that are part of
 `os` include `fspath`.

Exception raised on line 41 of file TESTS:\runtime\test_module_not_found_error.py.

   39:
   40:     try:
-->41:         import os.pathh
   42:     except ModuleNotFoundError as e:

Standard library module

Traceback (most recent call last):
  File "TESTS:\runtime\test_module_not_found_error.py", line 6, in test_Standard_library_module
    import Tkinter
ModuleNotFoundError: No module named 'Tkinter'

    Did you mean `tkinter`?

A `ModuleNotFoundError` exception indicates that you
are trying to import a module that cannot be found by Python.
This could be because you misspelled the name of the module
or because it is not installed on your computer.

The name of the module that could not be imported is `Tkinter`.
`tkinter` is an existing module that has a similar name.

Exception raised on line 6 of file TESTS:\runtime\test_module_not_found_error.py.

   4: def test_Standard_library_module():
   5:     try:
-->6:         import Tkinter
   7:     except ModuleNotFoundError as e:

NameError

Annotated variable

Traceback (most recent call last):
  File "TESTS:\runtime\test_name_error.py", line 21, in test_Annotated_variable
    y = x
NameError: name 'x' is not defined

    Did you use a colon instead of an equal sign?

A `NameError` exception indicates that a variable or
function name is not known to Python.
Most often, this is because there is a spelling mistake.
However, sometimes it is because the name is used
before being defined or given a value.

In your program, `x` is an unknown name.
A type hint found for `x` in the global scope.
Perhaps you had used a colon instead of an equal sign and wrote

    x : 3

instead of

    x = 3

Exception raised on line 21 of file TESTS:\runtime\test_name_error.py.

   19: def test_Annotated_variable():
   20:     try:
-->21:         y = x
                   ^
   22:     except NameError as e:

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_name_error.py", line 6, in test_Generic
    this = something
NameError: name 'something' is not defined

A `NameError` exception indicates that a variable or
function name is not known to Python.
Most often, this is because there is a spelling mistake.
However, sometimes it is because the name is used
before being defined or given a value.

In your program, `something` is an unknown name.
I have no additional information for you.

Exception raised on line 6 of file TESTS:\runtime\test_name_error.py.

   4: def test_Generic():
   5:     try:
-->6:         this = something
                     ^^^^^^^^^
   7:     except NameError as e:

Synonym

Traceback (most recent call last):
  File "TESTS:\runtime\test_name_error.py", line 86, in test_Synonym
    cost  # wrote from math import * above
NameError: name 'cost' is not defined

    Did you mean `cos`?

A `NameError` exception indicates that a variable or
function name is not known to Python.
Most often, this is because there is a spelling mistake.
However, sometimes it is because the name is used
before being defined or given a value.

In your program, `cost` is an unknown name.
Instead of writing `cost`, perhaps you meant one of the following:
*   Global scope: `cos`, `cosh`, `acos`

Exception raised on line 86 of file TESTS:\runtime\test_name_error.py.

   84:
   85:     try:
-->86:         cost  # wrote from math import * above
               ^^^^
   87:     except NameError as e:

OverflowError

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_overflow_error.py", line 6, in test_Generic
    2.0 ** 1600
OverflowError: (34, 'Result too large')

An `OverflowError` is raised when the result of an arithmetic operation
is too large to be handled by the computer's processor.

Exception raised on line 6 of file TESTS:\runtime\test_overflow_error.py.

   4: def test_Generic():
   5:     try:
-->6:         2.0 ** 1600
   7:     except OverflowError as e:

RecursionError

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_recursion_error.py", line 8, in test_Generic
    a()

       ... More lines not shown. ...

  File "TESTS:\runtime\test_recursion_error.py", line 6, in a
    return a()
  File "TESTS:\runtime\test_recursion_error.py", line 6, in a
    return a()
  File "TESTS:\runtime\test_recursion_error.py", line 6, in a
    return a()
RecursionError: maximum recursion depth exceeded

A `RecursionError` is raised when a function calls itself,
directly or indirectly, too many times.
It almost always indicates that you made an error in your code
and that your program would never stop.

Execution stopped on line 8 of file TESTS:\runtime\test_recursion_error.py.

    6:         return a()
    7:     try:
--> 8:         a()
    9:     except RecursionError as e:

        a: <function a> from test_Generic

Exception raised on line 6 of file TESTS:\runtime\test_recursion_error.py.

   4: def test_Generic():
   5:     def a():
-->6:         return a()
                     ^^^
   7:     try:

        a: <function a> from test_Generic

TypeError

Bad type for unary operator

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 371, in test_Bad_type_for_unary_operator
    a =+ "def"
TypeError: bad operand type for unary +: 'str'

    Perhaps you meant to write `+=` instead of `=+`
A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You tried to use the unary operator '+'
with the following type of object: a string (`str`).
This operation is not defined for this type of object.

Perhaps you meant to write `+=` instead of `=+`

Exception raised on line 371 of file TESTS:\runtime\test_type_error.py.

   369:         # fmt: off
   370:         a = "abc"
-->371:         a =+ "def"
                   ^^^^^^^
   372:         # fmt: on

Can only concatenate

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 37, in test_Can_only_concatenate
    result = a_tuple + a_list
TypeError: can only concatenate tuple (not "list") to tuple

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You tried to concatenate (add) two different types of objects:
a `tuple` and a `list`.

Exception raised on line 37 of file TESTS:\runtime\test_type_error.py.

   35:         a_tuple = (1, 2, 3)
   36:         a_list = [1, 2, 3]
-->37:         result = a_tuple + a_list
                        ^^^^^^^^^^^^^^^^
   38:     except TypeError as e:

        a_tuple: (1, 2, 3)
        a_list: [1, 2, 3]

Cannot convert dictionary update sequence

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 766, in test_Cannot_convert_dictionary_update_sequence
    dd.update([1, 2, 3])
TypeError: cannot convert dictionary update sequence element #0 to a sequence

    Perhaps you need to use the `dict.fromkeys()` method.

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

`dict.update()` does not accept a sequence as an argument.
Instead of writing `dd.update([1, 2, 3])`
perhaps you should use the `dict.fromkeys()` method: `dd.update( dict.fromkeys([1, 2, 3]) )`.

Exception raised on line 766 of file TESTS:\runtime\test_type_error.py.

   764:     dd = {"a": "a"}
   765:     try:
-->766:         dd.update([1, 2, 3])
   767:     except TypeError as e:

        dd: {'a': 'a'}
        dd.update: <builtin method update of dict object>

Cannot multiply by non int

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 570, in test_Cannot_multiply_by_non_int
    "a" * "2"
TypeError: can't multiply sequence by non-int of type 'str'

    Did you forget to convert `"2"` into an integer?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You can only multiply sequences, such as list, tuples,
 strings, etc., by integers.
Perhaps you forgot to convert `"2"` into an integer.

Exception raised on line 570 of file TESTS:\runtime\test_type_error.py.

   568:
   569:     try:
-->570:         "a" * "2"
   571:     except TypeError as e:

Cannot unpack non iterable object

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 738, in test_Cannot_unpack_non_iterable_object
    a, b = 42.0
TypeError: cannot unpack non-iterable float object

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

Unpacking is a convenient way to assign a name,
to each item of an iterable.
An iterable is an object capable of returning its members one at a time.
Python containers (`list, tuple, dict`, etc.) are iterables,
but not objects of type `float`.

Exception raised on line 738 of file TESTS:\runtime\test_type_error.py.

   736: def test_Cannot_unpack_non_iterable_object():
   737:     try:
-->738:         a, b = 42.0
   739:     except TypeError as e:

Comparison not supported

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 320, in test_Comparison_not_supported
    b >= a
TypeError: '>=' not supported between instances of 'int' and 'str'

    Did you forget to convert the string `a` into an integer (`int`)?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You tried to do an order comparison (>=)
between two incompatible types of objects:
an integer (`int`) and a string (`str`).
Perhaps you forgot to convert the string `a` into an integer (`int`).

Exception raised on line 320 of file TESTS:\runtime\test_type_error.py.

   318:         a = "2"
   319:         b = 42
-->320:         b >= a
   321:     except TypeError as e:

        b: 42
        a: '2'

Derive from BaseException

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 513, in test_Derive_from_BaseException
    raise "exception"  # noqa
TypeError: exceptions must derive from BaseException

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

In Python 3, exceptions must be derived from BaseException.

Exception raised on line 513 of file TESTS:\runtime\test_type_error.py.

   511: def test_Derive_from_BaseException():
   512:     try:
-->513:         raise "exception"  # noqa
   514:     except TypeError as e:

Indices must be integers or slices

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 652, in test_Indices_must_be_integers_or_slices
    [1, 2, 3]["2"]
TypeError: list indices must be integers or slices, not str

    Did you forget to convert `"2"` into an integer?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

In the expression `[1, 2, 3]["2"]`
what is included between the square brackets, `[...]`,
must be either an integer or a slice
(`start:stop` or `start:stop:step`)
and you have used a string (`str`) instead.

Perhaps you forgot to convert `"2"` into an integer.

Exception raised on line 652 of file TESTS:\runtime\test_type_error.py.

   650:
   651:     try:
-->652:         [1, 2, 3]["2"]
   653:     except TypeError as e:

Not an integer

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 615, in test_Not_an_integer
    range(c, d)
TypeError: 'str' object cannot be interpreted as an integer

    Did you forget to convert `c, d` into integers?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You wrote an object of type `str` where an integer was expected.
Perhaps you forgot to convert `c, d` into integers.
Exception raised on line 615 of file TESTS:\runtime\test_type_error.py.

   613:     c, d = "2", "3"
   614:     try:
-->615:         range(c, d)
   616:     except TypeError as e:

        c: '2'
        d: '3'
        range: <class range>

Not callable

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 500, in test_Not_callable
    _ = [1, 2](a + b)
TypeError: 'list' object is not callable

    Did you mean `[1, 2][a + b]`?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

Because of the surrounding parenthesis, `(a + b)`
is interpreted by Python as indicating a function call for
`[1, 2]`, which is an object of type `list`
which cannot be called.

However, `[1, 2]` is a sequence.
Perhaps you meant to use `[]` instead of `()` and write
`[1, 2][a + b]`

Exception raised on line 500 of file TESTS:\runtime\test_type_error.py.

   498:     try:
   499:         a, b = 3, 7
-->500:         _ = [1, 2](a + b)
                    ^^^^^^^^^^^^^
   501:     except TypeError as e:

        a: 3
        b: 7
        a + b: 10

Object is not iterable

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 724, in test_Object_is_not_iterable
    list(42)
TypeError: 'int' object is not iterable

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

An iterable is an object capable of returning its members one at a time.
Python containers (`list, tuple, dict`, etc.) are iterables.
An iterable is required here.

Exception raised on line 724 of file TESTS:\runtime\test_type_error.py.

   722: def test_Object_is_not_iterable():
   723:     try:
-->724:         list(42)
   725:     except TypeError as e:

        list: <class list>

Object is not subscriptable

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 710, in test_Object_is_not_subscriptable
    a = f[1]
TypeError: 'function' object is not subscriptable

    Did you mean `f(1)`?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

Subscriptable objects are typically containers from which
you can retrieve item using the notation `[...]`.

Perhaps you meant to write `f(1)`.

Exception raised on line 710 of file TESTS:\runtime\test_type_error.py.

   708:
   709:     try:
-->710:         a = f[1]
                    ^^^^
   711:     except TypeError as e:

        f: <function f> from test_Object_is_not_subscriptable

Slice indices must be integers or None

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 666, in test_Slice_indices_must_be_integers_or_None
    [1, 2, 3][1.0:2.0]
TypeError: slice indices must be integers or None or have an __index__ method

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

When using a slice to extract a range of elements
from a sequence, that is something like
`[start:stop]` or `[start:stop:step]`
each of `start`, `stop`, `step` must be either an integer, `None`,
or possibly some other object having an `__index__` method.

Exception raised on line 666 of file TESTS:\runtime\test_type_error.py.

   664: def test_Slice_indices_must_be_integers_or_None():
   665:     try:
-->666:         [1, 2, 3][1.0:2.0]
   667:     except TypeError as e:

Too few positional argument

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 441, in test_Too_few_positional_argument
    fn(1)
TypeError: fn() missing 2 required positional arguments: 'b' and 'c'

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You apparently have called the function 'fn()' with
fewer positional arguments than it requires (2 missing).

Exception raised on line 441 of file TESTS:\runtime\test_type_error.py.

   439:
   440:     try:
-->441:         fn(1)
   442:     except TypeError as e:

        fn: <function fn> from test_Too_few_positional_argument

Too many positional argument

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 422, in test_Too_many_positional_argument
    A().f(1)
TypeError: f() takes 1 positional argument but 2 were given

    Perhaps you forgot `self` when defining `f`.

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You apparently have called the function `f` with
2 positional argument(s) while it requires 1
such positional argument(s).
Perhaps you forgot `self` when defining `f`.

Exception raised on line 422 of file TESTS:\runtime\test_type_error.py.

   420:
   421:     try:
-->422:         A().f(1)
   423:     except TypeError as e:

        A: <class A> from test_type_error.test_Too_many_positional_argument

Tuple no item assignment

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 389, in test_Tuple_no_item_assignment
    a[0] = 0
TypeError: 'tuple' object does not support item assignment

    Did you mean to use a list?

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

In Python, some objects are known as immutable:
once defined, their value cannot be changed.
You tried change part of such an immutable object: a `tuple`,
most likely by using an indexing operation.
Perhaps you meant to use a list instead.

Exception raised on line 389 of file TESTS:\runtime\test_type_error.py.

   387:     a = (1, 2, 3)
   388:     try:
-->389:         a[0] = 0
   390:     except TypeError as e:

        a: (1, 2, 3)
        a[0]: 1

Unhachable type

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 683, in test_Unhachable_type
    {[1, 2]: 1}
TypeError: unhashable type: 'list'

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

Only hashable objects can be used
as elements of `set` or keys of `dict`.
Hashable objects are objects that do not change value
once they have been created.Instead of using a `list`, consider using a `tuple`.

Exception raised on line 683 of file TESTS:\runtime\test_type_error.py.

   681: def test_Unhachable_type():
   682:     try:
-->683:         {[1, 2]: 1}
   684:     except TypeError as e:

Unsupported operand types

Traceback (most recent call last):
  File "TESTS:\runtime\test_type_error.py", line 283, in test_Unsupported_operand_types
    a @= b
TypeError: unsupported operand type(s) for @=: 'str' and 'int'

A `TypeError` is usually caused by trying
to combine two incompatible types of objects,
by calling a function with the wrong type of object,
or by trying to do an operation not allowed on a given type of object.

You tried to use the operator @=
using two incompatible types of objects:
a string (`str`) and an integer (`int`).
This operator is normally used only
for multiplication of matrices.

Exception raised on line 283 of file TESTS:\runtime\test_type_error.py.

   281:         a = "a"
   282:         b = 2
-->283:         a @= b
   284:     except TypeError as e:

        a: 'a'
        b: 2

UnboundLocalError

Missing global

Traceback (most recent call last):
  File "TESTS:\runtime\test_unbound_local_error.py", line 27, in test_Missing_global
    outer_missing_global()
  File "TESTS:\runtime\test_unbound_local_error.py", line 11, in outer_missing_global
    inner()
  File "TESTS:\runtime\test_unbound_local_error.py", line 9, in inner
    spam_missing_global += 1
UnboundLocalError: local variable 'spam_missing_global' referenced before assignment

    Did you forget to add `global spam_missing_global`?

In Python, variables that are used inside a function are known as
local variables. Before they are used, they must be assigned a value.
A variable that is used before it is assigned a value is assumed to
be defined outside that function; it is known as a `global`
(or sometimes `nonlocal`) variable. You cannot assign a value to such
a global variable inside a function without first indicating to
Python that this is a global variable, otherwise you will see
an `UnboundLocalError`.

The name `spam_missing_global` exists in the global scope.
Perhaps the statement

    global spam_missing_global

should have been included as the first line inside your function.

Execution stopped on line 27 of file TESTS:\runtime\test_unbound_local_error.py.

   25:
   26:     try:
-->27:         outer_missing_global()
   28:     except UnboundLocalError as e:

        global outer_missing_global: <function outer_missing_global>

Exception raised on line 9 of file TESTS:\runtime\test_unbound_local_error.py.

    7: def outer_missing_global():
    8:     def inner():
--> 9:         spam_missing_global += 1

        global spam_missing_global: 1

Missing nonlocal

Traceback (most recent call last):
  File "TESTS:\runtime\test_unbound_local_error.py", line 48, in test_Missing_nonlocal
    outer_missing_nonlocal()
  File "TESTS:\runtime\test_unbound_local_error.py", line 20, in outer_missing_nonlocal
    inner()
  File "TESTS:\runtime\test_unbound_local_error.py", line 18, in inner
    spam_missing_nonlocal += 1
UnboundLocalError: local variable 'spam_missing_nonlocal' referenced before assignment

    Did you forget to add `nonlocal spam_missing_nonlocal`?

In Python, variables that are used inside a function are known as
local variables. Before they are used, they must be assigned a value.
A variable that is used before it is assigned a value is assumed to
be defined outside that function; it is known as a `global`
(or sometimes `nonlocal`) variable. You cannot assign a value to such
a global variable inside a function without first indicating to
Python that this is a global variable, otherwise you will see
an `UnboundLocalError`.

The name `spam_missing_nonlocal` exists in the nonlocal scope.
Perhaps the statement

    nonlocal spam_missing_nonlocal

should have been included as the first line inside your function.

Execution stopped on line 48 of file TESTS:\runtime\test_unbound_local_error.py.

   46:
   47:     try:
-->48:         outer_missing_nonlocal()
   49:     except UnboundLocalError as e:

        global outer_missing_nonlocal: <function outer_missing_nonlocal>

Exception raised on line 18 of file TESTS:\runtime\test_unbound_local_error.py.

   16:
   17:     def inner():
-->18:         spam_missing_nonlocal += 1

UnknownError

Generic

Traceback (most recent call last):
  File "TESTS:\runtime\test_unknown_error.py", line 10, in test_Generic
    raise MyException("Some informative message about an unknown exception.")
MyException: Some informative message about an unknown exception.

No information is known about this exception.
Please report this example to
https://github.com/aroberge/friendly/issues

If you are using the Friendly console, use `www()` to
do an Internet search for this particular case.

Exception raised on line 10 of file TESTS:\runtime\test_unknown_error.py.

    8: def test_Generic():
    9:     try:
-->10:         raise MyException("Some informative message about an unknown exception.")
   11:     except Exception as e:

        global MyException: <class test_unknown_error.MyException>

ValueError

Not enough values to unpack

Traceback (most recent call last):
  File "TESTS:\runtime\test_value_error.py", line 28, in test_Not_enough_values_to_unpack
    a, b, c = d
ValueError: not enough values to unpack (expected 3, got 2)

A `ValueError` indicates that a function or an operation
received an argument of the right type, but an inappropriate value.

Unpacking is a convenient way to assign a name,
to each item of an iterable.
In this instance, there are more names (3)
than the length of the iterable, a string (`str`) of length 2.

Exception raised on line 28 of file TESTS:\runtime\test_value_error.py.

   26:     d = "ab"
   27:     try:
-->28:         a, b, c = d
   29:     except ValueError as e:

        d: 'ab'

Too many values to unpack

Traceback (most recent call last):
  File "TESTS:\runtime\test_value_error.py", line 43, in test_Too_many_values_to_unpack
    a, b = c
ValueError: too many values to unpack (expected 2)

A `ValueError` indicates that a function or an operation
received an argument of the right type, but an inappropriate value.

Unpacking is a convenient way to assign a name,
to each item of an iterable.
In this instance, there are fewer names (2)
than the length of the iterable, a `list` of length 3.

Exception raised on line 43 of file TESTS:\runtime\test_value_error.py.

   41:     c = [1, 2, 3]
   42:     try:
-->43:         a, b = c
   44:     except ValueError as e:

        c: [1, 2, 3]

ZeroDivisionError

Complex division

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 97, in test_Complex_division
    1 / zero
ZeroDivisionError: complex division by zero

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

You are dividing by the following term

     zero

which is equal to zero.

Exception raised on line 97 of file TESTS:\runtime\test_zero_division_error.py.

   95:     zero = 0j
   96:     try:
-->97:         1 / zero
   98:     except ZeroDivisionError as e:

        zero: 0j

Division operator

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 7, in test_Division_operator
    1 / zero
ZeroDivisionError: division by zero

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

You are dividing by the following term

     zero

which is equal to zero.

Exception raised on line 7 of file TESTS:\runtime\test_zero_division_error.py.

   5:     zero = 0
   6:     try:
-->7:         1 / zero
   8:     except ZeroDivisionError as e:

        zero: 0

Divmod

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 52, in test_Divmod
    divmod(1, zero)
ZeroDivisionError: integer division or modulo by zero

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

The second argument of the `divmod()` function is zero.

Exception raised on line 52 of file TESTS:\runtime\test_zero_division_error.py.

   50:     zero = 0
   51:     try:
-->52:         divmod(1, zero)
   53:     except ZeroDivisionError as e:

        zero: 0
        divmod: <builtin function divmod>

Float division

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 82, in test_Float_division
    1 / zero
ZeroDivisionError: float division by zero

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

You are dividing by the following term

     zero

which is equal to zero.

Exception raised on line 82 of file TESTS:\runtime\test_zero_division_error.py.

   80:     zero = 0.
   81:     try:
-->82:         1 / zero
   83:     except ZeroDivisionError as e:

        zero: 0.0

Float modulo

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 67, in test_Float_modulo
    1 % zero
ZeroDivisionError: float modulo

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

Using the modulo operator, you are dividing by the following term

     zero

which is equal to zero.

Exception raised on line 67 of file TESTS:\runtime\test_zero_division_error.py.

   65:     zero = 0.
   66:     try:
-->67:         1 % zero
   68:     except ZeroDivisionError as e:

        zero: 0.0

Integer division operator

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 22, in test_Integer_division_operator
    1 // zero
ZeroDivisionError: integer division or modulo by zero

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

You are dividing by the following term

     zero

which is equal to zero.

Exception raised on line 22 of file TESTS:\runtime\test_zero_division_error.py.

   20:     zero = 0
   21:     try:
-->22:         1 // zero
   23:     except ZeroDivisionError as e:

        zero: 0

Modulo operator

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 37, in test_Modulo_operator
    1 % zero
ZeroDivisionError: integer division or modulo by zero

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

Using the modulo operator, you are dividing by the following term

     zero

which is equal to zero.

Exception raised on line 37 of file TESTS:\runtime\test_zero_division_error.py.

   35:     zero = 0
   36:     try:
-->37:         1 % zero
   38:     except ZeroDivisionError as e:

        zero: 0

Raise zero negative power

Traceback (most recent call last):
  File "TESTS:\runtime\test_zero_division_error.py", line 112, in test_Raise_zero_negative_power
    zero ** -1
ZeroDivisionError: 0.0 cannot be raised to a negative power

A `ZeroDivisionError` occurs when you are attempting to divide a value
by zero either directly or by using some other mathematical operation.

You are attempting to raise the number 0 to a negative power
which is equivalent to dividing by zero.

Exception raised on line 112 of file TESTS:\runtime\test_zero_division_error.py.

   110:     zero = 0
   111:     try:
-->112:         zero ** -1
   113:     except ZeroDivisionError as e:

        zero: 0