Friendly tracebacks - in English ====================================== Friendly 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. Not all cases handled by friendly are 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-traceback version: 0.7.53 Python version: 3.9.10 ArithmeticError --------------- Generic ~~~~~~~ .. code-block:: none 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. Exception raised on line `9` of file 'TESTS:\runtime\test_arithmetic_error.py'. 4| def test_Generic(): 5| try: 6| # I am not aware of any way in which this error is raised directly 7| # Usually, a subclass such as ZeroDivisionError, etc., would 8| # likely be raised. --> 9| raise ArithmeticError('error') 10| except ArithmeticError as e: ArithmeticError: AssertionError -------------- Generic ~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_assertion_error.py", line 8, in test_Generic raise AssertionError("Fake message") AssertionError: Fake message In Python, the keyword `assert` is used in statements of the form `assert condition`, to confirm that `condition` is not `False`, nor equivalent to `False` such as an empty list, etc. If `condition` is `False` or equivalent, an `AssertionError` is raised. Exception raised on line `8` of file 'TESTS:\runtime\test_assertion_error.py'. 4| def test_Generic(): 5| try: 6| # We raise it explicitly, rather than with the keyword assert, since 7| # we don't want pytest to rewrite out test. -->8| raise AssertionError("Fake message") 9| except AssertionError as e: AssertionError: AttributeError -------------- Attribute from other module ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 336, 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 `336` of file 'TESTS:\runtime\test_attribute_error.py'. 332| assert "Did you mean `math`?" in result 333| 334| import cmath 335| try: -->336| keyword.pi ^^^^^^^^^^ 337| except AttributeError as e: keyword: from PYTHON_LIB:\keyword.py Builtin function ~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 229, 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 `229` of file 'TESTS:\runtime\test_attribute_error.py'. 226| def test_Builtin_function(): 227| text = 'Hello world!' 228| try: -->229| len.text ^^^^^^^^ 230| except AttributeError as e: text: 'Hello world!' len: Builtin module with no file ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 247, 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 `247` of file 'TESTS:\runtime\test_attribute_error.py'. 243| """Issue 116""" 244| import sys 245| 246| try: -->247| sys.foo ^^^^^^^ 248| except AttributeError as e: sys: Circular import ~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 368, in test_Circular_import import my_turtle1 File "TESTS:\my_turtle1.py", line 4, in a = my_turtle1.something AttributeError: partially initialized module 'my_turtle1' has no attribute 'something' (most likely due to a circular import) 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`. I suspect that you used the name `my_turtle1.py` for your program and that you also wanted to import a module with the same name from Python's standard library. If so, you should use a different name for your program. Execution stopped on line `368` of file 'TESTS:\runtime\test_attribute_error.py'. 365| from friendly_traceback.runtime_errors import stdlib_modules 366| stdlib_modules.names.add("my_turtle1") 367| try: -->368| import my_turtle1 369| except AttributeError as e: Exception raised on line `4` of file 'TESTS:\my_turtle1.py'. 1| """To test attribute error of partially initialized module.""" 2| import my_turtle1 3| -->4| a = my_turtle1.something ^^^^^^^^^^^^^^^^^^^^ my_turtle1: from TESTS:\my_turtle1.py Circular import b ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 386, in test_Circular_import_b import circular_c File "TESTS:\circular_c.py", line 4, in a = circular_c.something AttributeError: partially initialized module 'circular_c' has no attribute 'something' (most likely due to a circular import) You have a circular import. An `AttributeError` occurs when the code contains something like `object.x` and `x` is not a method or attribute (variable) belonging to `object`. Python indicated that the module `{module}` was not fully imported. This can occur if, during the execution of the code in module `circular_c` an attempt is made to import the same module again. Execution stopped on line `386` of file 'TESTS:\runtime\test_attribute_error.py'. 384| def test_Circular_import_b(): 385| try: -->386| import circular_c 387| except AttributeError as e: Exception raised on line `4` of file 'TESTS:\circular_c.py'. 1| # Attribute error for partially initialize module 2| import circular_c 3| -->4| a = circular_c.something ^^^^^^^^^^^^^^^^^^^^ circular_c: from TESTS:\circular_c.py Generic ~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 26, in test_Generic A.x # testing type AttributeError: type object 'A' 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 `26` of file 'TESTS:\runtime\test_attribute_error.py'. 22| class A: 23| pass 24| 25| try: -->26| A.x # testing type ^^^ 27| except AttributeError as e: A: defined in Generic different frame ~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 50, in test_Generic_different_frame a.attr AttributeError: 'A' object has no attribute 'attr' Did you mean `attr2`? 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 `attr`. Perhaps you meant to write `a.attr2` instead of `a.attr` Exception raised on line `50` of file 'TESTS:\runtime\test_attribute_error.py'. 46| return A() 47| 48| a = f() 49| try: -->50| a.attr ^^^^^^ 51| except AttributeError as e: a: defined in .f> Generic instance ~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 69, in test_Generic_instance a.x 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 `69` of file 'TESTS:\runtime\test_attribute_error.py'. 66| pass 67| a = A() 68| try: -->69| a.x ^^^ 70| except AttributeError as e: a: defined in Module attribute typo ~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 150, 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` Exception raised on line `150` of file 'TESTS:\runtime\test_attribute_error.py'. 145| assert "Did you mean `ascii_lowercase`" in result 146| 147| import math 148| 149| try: -->150| math.cost ^^^^^^^^^ 151| except AttributeError as e: math: Nonetype ~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 191, 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 `191` of file 'TESTS:\runtime\test_attribute_error.py'. 188| def test_Nonetype(): 189| a = None 190| try: -->191| a.b ^^^ 192| except AttributeError as e: a: None Object attribute typo ~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 86, 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`. The object `a` has no attribute named `appendh`. Perhaps you meant to write `a.append` instead of `a.appendh` Exception raised on line `86` of file 'TESTS:\runtime\test_attribute_error.py'. 82| def test_Object_attribute_typo(): 83| # 84| try: 85| a = [1, 2, 3] -->86| a.appendh(4) ^^^^^^^^^ 87| except AttributeError as e: a: [1, 2, 3] Perhaps comma ~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 212, 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 `212` of file 'TESTS:\runtime\test_attribute_error.py'. 208| defg = "world" 209| 210| # fmt: off 211| try: -->212| a = [abcd ^^^^ 213| .defg] ^^^^^ 214| # fmt: on abcd: 'hello' defg: 'world' Read only ~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 289, in test_Read_only f.b = 1 AttributeError: 'F' object attribute 'b' is read-only An `AttributeError` occurs when the code contains something like `object.x` and `x` is not a method or attribute (variable) belonging to `object`. Object `f` uses `__slots__` to specify which attributes can be changed. The value of attribute `f.b` cannot be changed. The only attribute of `f` whose value can be changed is`a`. Exception raised on line `289` of file 'TESTS:\runtime\test_attribute_error.py'. 285| b = 2 286| 287| f = F() 288| try: -->289| f.b = 1 ^^^ 290| except AttributeError as e: f: defined in f.b: 2 Shadow stdlib module ~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 172, 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 `172` of file 'TESTS:\runtime\test_attribute_error.py'. 168| def test_Shadow_stdlib_module(): 169| import turtle 170| 171| try: -->172| turtle.Pen ^^^^^^^^^^ 173| except AttributeError as e: turtle: from TESTS:\turtle.py Tuple by accident ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 305, 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 `305` of file 'TESTS:\runtime\test_attribute_error.py'. 302| def test_Tuple_by_accident(): 303| something = "abc", # note trailing comma 304| try: -->305| something.upper() ^^^^^^^^^^^^^^^ 306| except AttributeError as e: something: ('abc',) Use builtin ~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 103, 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 `103` of file 'TESTS:\runtime\test_attribute_error.py'. 99| def test_Use_builtin(): 100| # 101| try: 102| a = [1, 2, 3] -->103| a.length() ^^^^^^^^ 104| except AttributeError as e: a: [1, 2, 3] Use join with str ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 351, in test_Use_join_with_str a = ['a', '2'].join('abc') + ['b', '3'].join('\n') AttributeError: 'list' object has no attribute 'join' Did you mean `'abc'.join(['a', '2'])`? 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', '2']` has no attribute named `join`. Perhaps you wanted something like `'abc'.join(['a', '2'])`. Exception raised on line `351` of file 'TESTS:\runtime\test_attribute_error.py'. 349| def test_Use_join_with_str(): 350| try: -->351| a = ['a', '2'].join('abc') + ['b', '3'].join('\n') ^^^^^^^^^^^^^^^ 352| except AttributeError as e: Use synonym ~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 120, 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 `120` of file 'TESTS:\runtime\test_attribute_error.py'. 116| def test_Use_synonym(): 117| # 118| try: 119| a = [1, 2, 3] -->120| a.add(4) ^^^^^ 121| except AttributeError as e: a: [1, 2, 3] Using slots ~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_attribute_error.py", line 268, 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 `268` of file 'TESTS:\runtime\test_attribute_error.py'. 264| __slots__ = ["a"] 265| 266| f = F() 267| try: -->268| f.b = 1 ^^^ 269| except AttributeError as e: f: defined in FileNotFoundError ----------------- Directory not found ~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_file_not_found_error.py", line 73, in test_Directory_not_found open("does_not_exist/file.txt") FileNotFoundError: [Errno 2] No such file or directory: 'does_not_exist/file.txt' 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 `file.txt`. does_not_exist is not a valid directory. Exception raised on line `73` of file 'TESTS:\runtime\test_file_not_found_error.py'. 71| def test_Directory_not_found(): 72| try: -->73| open("does_not_exist/file.txt") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 74| except FileNotFoundError as e: open: Filename not found ~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_file_not_found_error.py", line 7, in test_Filename_not_found 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`. It was expected to be found in the `C:\Users\Andre\github\friendly-traceback\tests` directory. I have no additional information for you. Exception raised on line `7` of file 'TESTS:\runtime\test_file_not_found_error.py'. 5| def test_Filename_not_found(): 6| try: -->7| open("does_not_exist") ^^^^^^^^^^^^^^^^^^^^^^ 8| except FileNotFoundError as e: open: Filename not found 2 ~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_file_not_found_error.py", line 31, in test_Filename_not_found_2 open("setupp.py") FileNotFoundError: [Errno 2] No such file or directory: 'setupp.py' Did you mean `setup.py`? 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 `setupp.py`. It was expected to be found in the `C:\Users\Andre\github\friendly-traceback` directory. The file `setup.py` has a similar name. Exception raised on line `31` of file 'TESTS:\runtime\test_file_not_found_error.py'. 27| if chdir: 28| os.chdir("..") 29| 30| try: -->31| open("setupp.py") ^^^^^^^^^^^^^^^^^ 32| except FileNotFoundError as e: open: Filename not found 3 ~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_file_not_found_error.py", line 54, in test_Filename_not_found_3 open("setup.pyg") FileNotFoundError: [Errno 2] No such file or directory: 'setup.pyg' Did you mean `setup.py`? 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 `setup.pyg`. It was expected to be found in the `C:\Users\Andre\github\friendly-traceback` directory. Perhaps you meant one of the following files with similar names: `setup.py`, `setup.cfg` Exception raised on line `54` of file 'TESTS:\runtime\test_file_not_found_error.py'. 51| if chdir: 52| os.chdir("..") 53| try: -->54| open("setup.pyg") ^^^^^^^^^^^^^^^^^ 55| except FileNotFoundError as e: open: ImportError ----------- Simple import error ~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_import_error.py", line 56, 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 `56` of file 'TESTS:\runtime\test_import_error.py'. 52| multiple_import_on_same_line() 53| wrong_case() 54| 55| try: -->56| from math import Pi 57| except ImportError as e: IndexError ---------- Assignment ~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_index_error.py", line 87, in test_Assignment a[13] = 1 IndexError: list assignment index out of range An `IndexError` occurs when you try to get an item from a list, a tuple, or a similar object (sequence), and use an index which does not exist; typically, this happens because the index you give is greater than the length of the sequence. You have tried to assign a value to index `13` of `a`, a `list` of length `10`. The valid index values of `a` are integers ranging from `-10` to `9`. Exception raised on line `87` of file 'TESTS:\runtime\test_index_error.py'. 83| assert "You have tried to assign a value to index `1` of `b`," in result 84| assert "a `list` which contains no item." in result 85| 86| try: -->87| a[13] = 1 ^^^^^ 88| except IndexError as e: a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Empty ~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_index_error.py", line 42, in test_Empty c = a[1] IndexError: list index out of range `a` contains no item. An `IndexError` occurs when you try to get an item from a list, a tuple, or a similar object (sequence), and use an index which does not exist; typically, this happens because the index you give is greater than the length of the sequence. You have tried to get the item with index `1` of `a`, a `list` which contains no item. Exception raised on line `42` of file 'TESTS:\runtime\test_index_error.py'. 39| def test_Empty(): 40| a = [] 41| try: -->42| c = a[1] ^^^^ 43| except IndexError as e: a: [] Long list ~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_index_error.py", line 27, in test_Long_list print(a[60], b[0]) IndexError: list index out of range An `IndexError` occurs when you try to get an item from a list, a tuple, or a similar object (sequence), and use an index which does not exist; typically, this happens because the index you give is greater than the length of the sequence. You have tried to get the item with index `60` of `a`, a `list` of length `40`. The valid index values of `a` are integers ranging from `-40` to `39`. Exception raised on line `27` of file 'TESTS:\runtime\test_index_error.py'. 24| a = list(range(40)) 25| b = tuple(range(50)) 26| try: -->27| print(a[60], b[0]) ^^^^^ 28| 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 ~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_index_error.py", line 10, in test_Short_tuple print(a[3], b[2]) IndexError: tuple index out of range Remember: the first item of a `tuple` is not at index 1 but at index 0. An `IndexError` occurs when you try to get an item from a list, a tuple, or a similar object (sequence), and use an index which does not exist; typically, this happens 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 valid index values of `a` are integers ranging from `-3` to `2`. Exception raised on line `10` of file 'TESTS:\runtime\test_index_error.py'. 7| a = (1, 2, 3) 8| b = [1, 2, 3] 9| try: -->10| print(a[3], b[2]) ^^^^ 11| except IndexError as e: a: (1, 2, 3) KeyError -------- ChainMap ~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "PYTHON_LIB:\collections\__init__.py", line 1008, 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 65, in test_ChainMap d.pop(42) 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 or in a similar object. The key `42` cannot be found in `d`, an object of type `ChainMap`. Exception raised on line `65` of file 'TESTS:\runtime\test_key_error.py'. 62| from collections import ChainMap 63| d = ChainMap({}, {}) 64| try: -->65| d.pop(42) ^^^^^^^^^ 66| except KeyError as e: d: ChainMap({}, {}) d.pop: of ChainMap({}, {}) Forgot to convert to string ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_key_error.py", line 120, in test_Forgot_to_convert_to_string print(squares[2]) KeyError: 2 Did you forget to convert `2` into a string? A `KeyError` is raised when a value is not found as a key in a Python dict or in a similar object. The key `2` cannot be found in the dict `squares`. `squares` contains a string key which is identical to `str(2)`. Perhaps you forgot to convert the key into a string. Exception raised on line `120` of file 'TESTS:\runtime\test_key_error.py'. 117| def test_Forgot_to_convert_to_string(): 118| squares = {"1": 1, "2": 4, "3": 9} 119| try: -->120| print(squares[2]) ^^^^^^^^^^ 121| except KeyError as e: squares: {'1': 1, '2': 4, '3': 9} Generic key error ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_key_error.py", line 46, in test_Generic_key_error d["c"] KeyError: 'c' A `KeyError` is raised when a value is not found as a key in a Python dict or in a similar object. The key `'c'` cannot be found in the dict `d`. Exception raised on line `46` of file 'TESTS:\runtime\test_key_error.py'. 43| def test_Generic_key_error(): 44| d = {"a": 1, "b": 2} 45| try: -->46| d["c"] ^^^^^^ 47| except KeyError as e: d: {'a': 1, 'b': 2} Popitem empty ChainMap ~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "PYTHON_LIB:\collections\__init__.py", line 1001, in popitem return self.maps[0].popitem() KeyError: 'popitem(): dictionary is empty' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "TESTS:\runtime\test_key_error.py", line 27, in test_Popitem_empty_ChainMap alpha.popitem() KeyError: 'No keys found in the first mapping.' `alpha` is an empty `ChainMap`. A `KeyError` is raised when a value is not found as a key in a Python dict or in a similar object. You tried to retrieve an item from `alpha` which is an empty `ChainMap`. Exception raised on line `27` of file 'TESTS:\runtime\test_key_error.py'. 24| from collections import ChainMap 25| alpha = ChainMap({}, {}) 26| try: -->27| alpha.popitem() ^^^^^^^^^^^^^^^ 28| except KeyError as e: alpha: ChainMap({}, {}) alpha.popitem: of ChainMap({}, {}) Popitem empty dict ~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_key_error.py", line 8, in test_Popitem_empty_dict d.popitem() KeyError: 'popitem(): dictionary is empty' `d` is an empty `dict`. A `KeyError` is raised when a value is not found as a key in a Python dict or in a similar object. You tried to retrieve an item from `d` which is an empty `dict`. Exception raised on line `8` of file 'TESTS:\runtime\test_key_error.py'. 5| def test_Popitem_empty_dict(): 6| d = {} 7| try: -->8| d.popitem() ^^^^^^^^^^^ 9| except KeyError as e: d: {} d.popitem: Similar names ~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_key_error.py", line 151, in test_Similar_names a = second["alpha"] KeyError: 'alpha' Did you mean `'alpha0'`? A `KeyError` is raised when a value is not found as a key in a Python dict or in a similar object. The key `'alpha'` cannot be found in the dict `second`. `second` has some keys similar to `'alpha'` including: `'alpha0', 'alpha11', 'alpha12'`. Exception raised on line `151` of file 'TESTS:\runtime\test_key_error.py'. 147| assert ok, diff 148| 149| second = {"alpha0": 1, "alpha11": 2, "alpha12": 3} 150| try: -->151| a = second["alpha"] ^^^^^^^^^^^^^^^ 152| except KeyError as e: second: {'alpha0': 1, 'alpha11': 2, 'alpha12': 3} String by mistake ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_key_error.py", line 102, in test_String_by_mistake d["(0, 0)"] KeyError: '(0, 0)' Did you convert `(0, 0)` into a string by mistake? A `KeyError` is raised when a value is not found as a key in a Python dict or in a similar object. The key `'(0, 0)'` cannot be found in the dict `d`. `'(0, 0)'` is a string. There is a key of `d` whose string representation is identical to `'(0, 0)'`. Exception raised on line `102` of file 'TESTS:\runtime\test_key_error.py'. 98| chain_map_string_by_mistake() # do not show in docs 99| 100| d = {(0, 0): "origin"} 101| try: -->102| d["(0, 0)"] ^^^^^^^^^^^ 103| except KeyError as e: d: {(0, 0): 'origin'} LookupError ----------- Generic ~~~~~~~ .. code-block:: none 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'. 4| def test_Generic(): 5| try: 6| # LookupError is the base class for KeyError and IndexError. 7| # It should normally not be raised by user code, 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: ModuleNotFoundError ------------------- Need to install module ~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 80, in test_Need_to_install_module import alphabet ModuleNotFoundError: No module named 'alphabet' 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. No module named `alphabet` can be imported. Perhaps you need to install it. Exception raised on line `80` of file 'TESTS:\runtime\test_module_not_found_error.py'. 78| def test_Need_to_install_module(): 79| try: -->80| import alphabet 81| except ModuleNotFoundError as e: Not a package ~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 23, in test_Not_a_package import os.xxx ModuleNotFoundError: No module named 'os.xxx'; 'os' is not a package 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. `xxx` cannot be imported from `os`. Exception raised on line `23` of file 'TESTS:\runtime\test_module_not_found_error.py'. 20| def test_Not_a_package(): 21| 22| try: -->23| import os.xxx 24| except ModuleNotFoundError as e: Not a package similar name ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 37, in test_Not_a_package_similar_name 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`. Exception raised on line `37` of file 'TESTS:\runtime\test_module_not_found_error.py'. 35| def test_Not_a_package_similar_name(): 36| try: -->37| import os.pathh 38| except ModuleNotFoundError as e: Object not module ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 51, in test_Object_not_module import os.open ModuleNotFoundError: No module named 'os.open'; 'os' is not a package Did you mean `from os import open`? 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. `open` is not a separate module but an object that is part of `os`. Exception raised on line `51` of file 'TESTS:\runtime\test_module_not_found_error.py'. 49| def test_Object_not_module(): 50| try: -->51| import os.open 52| except ModuleNotFoundError as e: open: Similar object not module ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 65, in test_Similar_object_not_module import os.opend ModuleNotFoundError: No module named 'os.opend'; 'os' is not a package Did you mean `from os import open`? 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 `from os import open`. `open` is a name similar to `opend` and is an object that can be imported from `os`. Other objects with similar names that are part of `os` include `popen`. Exception raised on line `65` of file 'TESTS:\runtime\test_module_not_found_error.py'. 63| def test_Similar_object_not_module(): 64| try: -->65| import os.opend 66| except ModuleNotFoundError as e: Standard library module ~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 7, 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. No module named `Tkinter` can be imported. Perhaps you need to install it. `tkinter` is an existing module that has a similar name. Exception raised on line `7` of file 'TESTS:\runtime\test_module_not_found_error.py'. 5| def test_Standard_library_module(): 6| try: -->7| import Tkinter 8| except ModuleNotFoundError as e: no curses ~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_module_not_found_error.py", line 97, in test_no_curses import curses ModuleNotFoundError: No module named '_curses' The curses module is rarely installed with Python on Windows. 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. You have tried to import the curses module. The curses module is rarely installed with Python on Windows. Exception raised on line `97` of file 'TESTS:\runtime\test_module_not_found_error.py'. 95| def test_no_curses(): 96| try: -->97| import curses 98| except ModuleNotFoundError as e: NameError --------- Annotated variable ~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 31, 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, no object with the name `x` exists. 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 `31` of file 'TESTS:\runtime\test_name_error.py'. 29| def test_Annotated_variable(): 30| try: -->31| y = x ^ 32| except NameError as e: Custom name ~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 234, in test_Custom_name python NameError: name 'python' is not defined You are already using Python! 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. You are already using Python! Exception raised on line `234` of file 'TESTS:\runtime\test_name_error.py'. 232| def test_Custom_name(): 233| try: -->234| python ^^^^^^ 235| except NameError as e: Free variable referenced ~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 217, in test_Free_variable_referenced outer() File "TESTS:\runtime\test_name_error.py", line 213, in outer inner() File "TESTS:\runtime\test_name_error.py", line 212, in inner return var NameError: free variable 'var' referenced before assignment in enclosing scope 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, `var` is an unknown name that exists in an enclosing scope, but has not yet been assigned a value. Execution stopped on line `217` of file 'TESTS:\runtime\test_name_error.py'. 213| inner() 214| var = 4 215| 216| try: -->217| outer() ^^^^^^^ 218| except NameError as e: outer: defined in Exception raised on line `212` of file 'TESTS:\runtime\test_name_error.py'. 211| def inner(): -->212| return var ^^^ Generic ~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 15, 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, no object with the name `something` exists. I have no additional information for you. Exception raised on line `15` of file 'TESTS:\runtime\test_name_error.py'. 13| def test_Generic(): 14| try: -->15| this = something ^^^^^^^^^ 16| except NameError as e: Missing import ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 138, in test_Missing_import unicodedata.something NameError: name 'unicodedata' is not defined Did you forget to import `unicodedata`? 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. The name `unicodedata` is not defined in your program. Perhaps you forgot to import `unicodedata` which is found in Python's standard library. Exception raised on line `138` of file 'TESTS:\runtime\test_name_error.py'. 134| if friendly_traceback.get_lang() == "en": 135| assert "I have no additional information for you." in result 136| 137| try: -->138| unicodedata.something ^^^^^^^^^^^ 139| except NameError as e: Missing module name ~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 320, in test_Missing_module_name frame = Frame() NameError: name 'Frame' is not defined Did you forget to add `tkinter.`? 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, no object with the name `Frame` exists. The global object `tkinter` has an attribute named `Frame`. Perhaps you should have written `tkinter.Frame` instead of `Frame`. `Frame` is a name found in the following modules: tkinter, tracemalloc. Perhaps you forgot to import `Frame` from one of these modules. Exception raised on line `320` of file 'TESTS:\runtime\test_name_error.py'. 317| @pytest.mark.skipif(not tkinter, reason="tkinter not present; likely MacOS") 318| def test_Missing_module_name(): 319| try: -->320| frame = Frame() ^^^^^ 321| except NameError as e: Missing self 1 ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 270, in test_Missing_self_1 str(a) File "TESTS:\runtime\test_name_error.py", line 261, in __str__ toys_list = add_toy( # ensure that it can see 'self' on following line NameError: name 'add_toy' is not defined Did you write `self` at the wrong place? 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, no object with the name `add_toy` exists. The local object ` defined in ` has an attribute named `add_toy`. Perhaps you should have written `self.add_toy(...` instead of `add_toy(self, ...`. Execution stopped on line `270` of file 'TESTS:\runtime\test_name_error.py'. 266| return "{} has no toys".format(self.name) 267| 268| a = Pet('Fido') 269| try: -->270| str(a) ^^^^^^ 271| except NameError as e: a: defined in str: Exception raised on line `261` of file 'TESTS:\runtime\test_name_error.py'. 259| def __str__(self): 260| # self at the wrong place -->261| toys_list = add_toy( # ensure that it can see 'self' on following line ^^^^^^^ 262| self, 'something') 263| if self.toys: Missing self 2 ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 305, in test_Missing_self_2 str(a) File "TESTS:\runtime\test_name_error.py", line 297, in __str__ toys_list = add_toy('something') NameError: name 'add_toy' is not defined Did you forget to add `self.`? 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, no object with the name `add_toy` exists. A local object, ` defined in `, has an attribute named `add_toy`. Perhaps you should have written `self.add_toy` instead of `add_toy`. Execution stopped on line `305` of file 'TESTS:\runtime\test_name_error.py'. 301| return "{} has no toys".format(self.name) 302| 303| a = Pet('Fido') 304| try: -->305| str(a) ^^^^^^ 306| except NameError as e: a: defined in str: Exception raised on line `297` of file 'TESTS:\runtime\test_name_error.py'. 295| def __str__(self): 296| # Missing self. -->297| toys_list = add_toy('something') ^^^^^^^ 298| if self.toys: Synonym ~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 97, 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, no object with the name `cost` exists. Instead of writing `cost`, perhaps you meant one of the following: * Global scope: `cos`, `cosh` Exception raised on line `97` of file 'TESTS:\runtime\test_name_error.py'. 93| if friendly_traceback.get_lang() == "en": 94| assert "The Python builtin `chr` has a similar name." in result 95| 96| try: -->97| cost # wrote from math import * above ^^^^ 98| except NameError as e: missing import2 ~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 153, in test_missing_import2 ABCMeta NameError: name 'ABCMeta' 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, no object with the name `ABCMeta` exists. `ABCMeta` is a name found in the following modules: selectors, typing, abc, numbers. Perhaps you forgot to import `ABCMeta` from one of these modules. Exception raised on line `153` of file 'TESTS:\runtime\test_name_error.py'. 151| def test_missing_import2(): 152| try: -->153| ABCMeta ^^^^^^^ 154| except NameError as e: missing import3 ~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 168, in test_missing_import3 AF_APPLETALK NameError: name 'AF_APPLETALK' 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, no object with the name `AF_APPLETALK` exists. `AF_APPLETALK` is a name found in module `socket`. Perhaps you forgot to write from socket import AF_APPLETALK Exception raised on line `168` of file 'TESTS:\runtime\test_name_error.py'. 166| def test_missing_import3(): 167| try: -->168| AF_APPLETALK ^^^^^^^^^^^^ 169| except NameError as e: missing import from other 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 183, in test_missing_import_from_other_1 plt.something NameError: name 'plt' is not defined Did you forget to import `matplotlib.pyplot`? 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. The name `plt` is not defined in your program. Perhaps you forgot to write import matplotlib.pyplot as plt Exception raised on line `183` of file 'TESTS:\runtime\test_name_error.py'. 180| def test_missing_import_from_other_1(): 181| friendly_traceback.add_other_module_names_synonyms({"plt": "matplotlib.pyplot"}) 182| try: -->183| plt.something ^^^ 184| except NameError as e: missing import from other 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 197, in test_missing_import_from_other_2 show() NameError: name 'show' 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, no object with the name `show` exists. `show` is a name found in the following modules: mailcap, matplotlib.pyplot, funny. Perhaps you forgot to import `show` from one of these modules. Exception raised on line `197` of file 'TESTS:\runtime\test_name_error.py'. 194| def test_missing_import_from_other_2(): 195| friendly_traceback.add_other_attribute_names({"show": ["matplotlib.pyplot", "funny"] }) 196| try: -->197| show() ^^^^ 198| except NameError as e: special keyword ~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_name_error.py", line 352, in test_special_keyword brek NameError: name 'brek' is not defined Did you mean `break`? 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. I suspect you meant to write the keyword `break` and made a typo. Exception raised on line `352` of file 'TESTS:\runtime\test_name_error.py'. 349| if friendly_traceback.get_lang() == "en": 350| assert "Did you mean `continue`" in result 351| try: -->352| brek ^^^^ 353| except NameError as e: OsError ------- Urllib error ~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "PYTHON_LIB:\urllib\request.py", line 1346, in do_open ... More lines not shown. ... File "PYTHON_LIB:\socket.py", line 823, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "PYTHON_LIB:\socket.py", line 954, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "TESTS:\runtime\test_os_error.py", line 10, in test_Urllib_error request.urlopen("http://does_not_exist") URLError: An exception of type `URLError` is a subclass of `OSError`. Nothing more specific is known about `URLError`. An `OSError` exception is usually raised by the Operating System to indicate that an operation is not allowed or that a resource is not available. I suspect that you are trying to connect to a server and that a connection cannot be made. If that is the case, check for typos in the URL and check your internet connectivity. Exception raised on line `10` of file 'TESTS:\runtime\test_os_error.py'. 6| @pytest.mark.skipif(random.randint(0, 50) < 59, reason="very long test") 7| def test_Urllib_error(): 8| from urllib import request, error 9| try: -->10| request.urlopen("http://does_not_exist") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11| except error.URLError as e: request: from PYTHON_LIB:\urllib\request.py request.urlopen: invalid argument ~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_os_error.py", line 50, in test_invalid_argument open("c:\test.txt") OSError: [Errno 22] Invalid argument: 'c:\test.txt' Perhaps you need to double the backslash characters. An `OSError` exception is usually raised by the Operating System to indicate that an operation is not allowed or that a resource is not available. I suspect that you wrote a filename or path that contains at least one backslash character, `\`. Python likely interpreted this as indicating the beginning of what is known as an escape sequence. To solve the problem, either write a so-called 'raw string' by adding the letter `r` as a prefix in front of the filename or path, or replace all single backslash characters, `\`, by double ones: `\\`. Exception raised on line `50` of file 'TESTS:\runtime\test_os_error.py'. 47| if os.name != "nt": 48| return "Windows test only", "No result" 49| try: -->50| open("c:\test.txt") ^^^^^^^^^^^^^^^^^^^ 51| except OSError as e: open: no information ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_os_error.py", line 30, in test_no_information raise OSError("Some unknown message") OSError: Some unknown message Friendly-traceback does not know the cause of this error. An `OSError` exception is usually raised by the Operating System to indicate that an operation is not allowed or that a resource is not available. No information is known about this exception. Please report this example to https://github.com/friendly-traceback/friendly-traceback/issues/new If you are using a REPL, use `www('bug')` to do so. If you are using the Friendly console, use `www()` to do an Internet search for this particular case. Exception raised on line `30` of file 'TESTS:\runtime\test_os_error.py'. 27| old_debug = friendly_traceback.debug_helper.DEBUG 28| friendly_traceback.debug_helper.DEBUG = False 29| try: -->30| raise OSError("Some unknown message") 31| except OSError as e: OSError: OverflowError ------------- Generic ~~~~~~~ .. code-block:: none 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: Huge lenght ~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_overflow_error.py", line 25, in test_Huge_lenght len(huge) OverflowError: Python int too large to convert to C ssize_t 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 `25` of file 'TESTS:\runtime\test_overflow_error.py'. 22| def test_Huge_lenght(): 23| huge = range(1<<10000) 24| try: -->25| len(huge) ^^^^^^^^^ 26| except OverflowError as e: huge: range(0, ...) len(huge): Object too large to be processed by Python. len: RecursionError -------------- Generic ~~~~~~~ .. code-block:: none 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() 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'. 5| def a(): 6| return a() 7| try: -->8| a() ^^^ 9| except RecursionError as e: a: defined in Exception raised on line `6` of file 'TESTS:\runtime\test_recursion_error.py'. 5| def a(): -->6| return a() ^^^ a: defined in TypeError --------- Argument of object is not iterable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 843, in test_Argument_of_object_is_not_iterable a in b TypeError: argument of type '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. 'b' is not a container. A container is required here. Exception raised on line `843` of file 'TESTS:\runtime\test_type_error.py'. 840| a = object() 841| b = object() 842| try: -->843| a in b ^^^^^^ 844| except TypeError as e: a: b: Bad type for unary operator ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 427, 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 `427` of file 'TESTS:\runtime\test_type_error.py'. 422| assert "You tried to use the unary operator '~'" in result 423| 424| try: 425| # fmt: off 426| a = "abc" -->427| a =+ "def" ^^^^^^^ 428| # fmt: on Builtin has no len ~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 901, in test_Builtin_has_no_len len("Hello world".split) TypeError: object of type 'builtin_function_or_method' has no len() Did you forget to call `"Hello world".split`? 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. I suspect that you forgot to add parentheses to call `"Hello world".split`. You might have meant to write: `len("Hello world".split())` Exception raised on line `901` of file 'TESTS:\runtime\test_type_error.py'. 899| def test_Builtin_has_no_len(): 900| try: -->901| len("Hello world".split) ^^^^^^^^^^^^^^^^^^^^^^^^ 902| except TypeError as e: len: "Hello world".split: Can only concatenate ~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 39, 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 `39` of file 'TESTS:\runtime\test_type_error.py'. 36| try: 37| a_tuple = (1, 2, 3) 38| a_list = [1, 2, 3] -->39| result = a_tuple + a_list ^^^^^^^^^^^^^^^^ 40| except TypeError as e: a_list: [1, 2, 3] a_tuple: (1, 2, 3) Cannot convert dictionary update sequence ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 886, 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 `886` of file 'TESTS:\runtime\test_type_error.py'. 882| assert "you should use the `dict.fromkeys()`" in result 883| 884| dd = {"a": "a"} 885| try: -->886| dd.update([1, 2, 3]) ^^^^^^^^^^^^^^^^^^^^ 887| except TypeError as e: dd: {'a': 'a'} dd.update: Cannot multiply by non int ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 652, 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 `652` of file 'TESTS:\runtime\test_type_error.py'. 648| if friendly_traceback.get_lang() == "en": 649| assert "Did you forget to convert `c` into an integer?" in result 650| 651| try: -->652| "a" * "2" ^^^^^^^^^ 653| except TypeError as e: Cannot unpack non iterable object ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 857, 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 `857` of file 'TESTS:\runtime\test_type_error.py'. 855| def test_Cannot_unpack_non_iterable_object(): 856| try: -->857| a, b = 42.0 858| except TypeError as e: Cant mod complex numbers ~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 54, in test_Cant_mod_complex_numbers 3 + 3j % 2 TypeError: can't mod complex numbers. 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 cannot use complex numbers with the modulo operator `%`. Exception raised on line `54` of file 'TESTS:\runtime\test_type_error.py'. 52| def test_Cant_mod_complex_numbers(): 53| try: -->54| 3 + 3j % 2 ^^^^^^ 55| except TypeError as e: Comparison not supported ~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 375, 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 `375` of file 'TESTS:\runtime\test_type_error.py'. 372| try: 373| a = "2" 374| b = 42 -->375| b >= a ^^^^^^ 376| except TypeError as e: a: '2' b: 42 Derive from BaseException ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 594, 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. Exceptions must be derived from `BaseException`. It is recommended that user-defined exceptions derive from `Exception`, a subclass of `BaseException`. Exception raised on line `594` of file 'TESTS:\runtime\test_type_error.py'. 590| if friendly_traceback.get_lang() == "en": 591| assert "you must only have classes that derive from `BaseException`" in result 592| 593| try: -->594| raise "exception" # noqa 595| except TypeError as e: Generator has no len ~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 1062, in test_Generator_has_no_len nb = len(letter TypeError: object of type 'generator' has no len() You likely need to build a list first. 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. I am guessing that you were trying to count the number of elements produced by a generator expression. You first need to capture them in a list: len([letter for letter in "word"]) Exception raised on line `1062` of file 'TESTS:\runtime\test_type_error.py'. 1060| def test_Generator_has_no_len(): 1061| try: -->1062| nb = len(letter ^^^^^^^^^^ 1063| for letter in "word") ^^^^^^^^^^^^^^^^^^^^^ 1064| except TypeError as e: len: Indices must be integers or slices ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 736, 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 `736` of file 'TESTS:\runtime\test_type_error.py'. 732| if friendly_traceback.get_lang() == "en": 733| assert "Perhaps you forgot to convert `2.0` into an integer." in result 734| 735| try: -->736| [1, 2, 3]["2"] ^^^^^^^^^^^^^^ 737| except TypeError as e: Not an integer ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 698, 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 `698` of file 'TESTS:\runtime\test_type_error.py'. 694| assert "Perhaps you forgot to convert `1.0" in result 695| 696| c, d = "2", "3" 697| try: -->698| range(c, d) ^^^^^^^^^^^ 699| except TypeError as e: c: '2' d: '3' range: Not callable ~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 561, 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 `561` of file 'TESTS:\runtime\test_type_error.py'. 557| assert "b.a_list[3]" in result 558| 559| try: 560| a, b = 3, 7 -->561| _ = [1, 2](a + b) ^^^^^^^^^^^^^ 562| except TypeError as e: a: 3 b: 7 a + b: 10 Object is not iterable ~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 826, 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 `826` of file 'TESTS:\runtime\test_type_error.py'. 824| def test_Object_is_not_iterable(): 825| try: -->826| list(42) ^^^^^^^^ 827| except TypeError as e: list: Object is not subscriptable ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 811, 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 `811` of file 'TESTS:\runtime\test_type_error.py'. 807| def f(): 808| pass 809| 810| try: -->811| a = f[1] ^^^^ 812| except TypeError as e: f: defined in Slice indices must be integers or None ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 751, 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 `751` of file 'TESTS:\runtime\test_type_error.py'. 749| def test_Slice_indices_must_be_integers_or_None(): 750| try: -->751| [1, 2, 3][1.0:2.0] ^^^^^^^^^^^^^^^^^^ 752| except TypeError as e: Too few positional argument ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 500, 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 `500` of file 'TESTS:\runtime\test_type_error.py'. 496| def fn(a, b, c): 497| pass 498| 499| try: -->500| fn(1) ^^^^^ 501| except TypeError as e: fn: defined in Too many positional argument ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 480, 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 `480` of file 'TESTS:\runtime\test_type_error.py'. 476| def f(x): 477| pass 478| 479| try: -->480| A().f(1) ^^^^^^^^ 481| except TypeError as e: A: defined in Tuple no item assignment ~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 446, 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 `446` of file 'TESTS:\runtime\test_type_error.py'. 443| def test_Tuple_no_item_assignment(): 444| a = (1, 2, 3) 445| try: -->446| a[0] = 0 ^^^^ 447| except TypeError as e: a: (1, 2, 3) a[0]: 1 Unhachable type ~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 769, 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 `769` of file 'TESTS:\runtime\test_type_error.py'. 767| def test_Unhachable_type(): 768| try: -->769| {[1, 2]: 1} 770| except TypeError as e: Unsupported operand types ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 325, 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 `325` of file 'TESTS:\runtime\test_type_error.py'. 322| try: 323| a = "a" 324| b = 2 -->325| a @= b 326| except TypeError as e: a: 'a' b: 2 divmod ~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 69, in test_divmod result = divmod(a, b) TypeError: can't take floor or mod of complex number. 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. The arguments of `divmod` must be integers (`int`) or real (`float`) numbers. At least one of the arguments was a complex number. Exception raised on line `69` of file 'TESTS:\runtime\test_type_error.py'. 66| a = 2 67| b = 3 + 2j 68| try: -->69| result = divmod(a, b) ^^^^^^^^^^^^ 70| except TypeError as e: a: 2 b: (3+2j) divmod: function got multiple argument ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 996, in test_function_got_multiple_argument fn2(0, a=1) TypeError: fn2() got multiple values for argument 'a' 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 have specified the value of argument `a` more than once when calling the function named `fn2`. This function has the following arguments: `a, b=1` Exception raised on line `996` of file 'TESTS:\runtime\test_type_error.py'. 992| def fn2(a, b=1): 993| pass 994| 995| try: -->996| fn2(0, a=1) ^^^^^^^^^^^ 997| except TypeError as e: fn2: defined in function has no len ~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 919, in test_function_has_no_len len(bad) TypeError: object of type 'function' has no len() Did you forget to call `bad`? 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. I suspect that you forgot to add parentheses to call `bad`. You might have meant to write: `len(bad())` Exception raised on line `919` of file 'TESTS:\runtime\test_type_error.py'. 915| def bad(): 916| pass 917| 918| try: -->919| len(bad) ^^^^^^^^ 920| except TypeError as e: bad: defined in len: getattr attribute name must be string ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 1044, in test_getattr_attribute_name_must_be_string getattr("__repr__", 1) # as reported in issue #77 TypeError: getattr(): attribute name must be string 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. The second argument of the function `getattr()` must be a string. Exception raised on line `1044` of file 'TESTS:\runtime\test_type_error.py'. 1037| if friendly_traceback.get_lang() == "en": 1038| assert ( 1039| "The second argument of the function `hasattr()` must be a string." 1040| in result 1041| ) 1042| 1043| try: -->1044| getattr("__repr__", 1) # as reported in issue #77 ^^^^^^^^^^^^^^^^^^^^^^ 1045| except TypeError as e: getattr: method got multiple argument ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 1016, in test_method_got_multiple_argument t.some_method(0, a=1) TypeError: some_method() got multiple values for argument 'a' 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 have specified the value of argument `a` more than once when calling the function named `t.some_method`. This function has only one argument: `a` Exception raised on line `1016` of file 'TESTS:\runtime\test_type_error.py'. 1012| pass 1013| 1014| t = T() 1015| try: -->1016| t.some_method(0, a=1) ^^^^^^^^^^^^^^^^^^^^^ 1017| except TypeError as e: t: defined in t.some_method: of defined in vars arg must have dict ~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_type_error.py", line 964, in test_vars_arg_must_have_dict vars(f) TypeError: vars() argument must have __dict__ attribute 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. The function `vars` is used to list the content of the `__dict__` attribute of an object. Object `f` uses `__slots__` instead of `__dict__`. Exception raised on line `964` of file 'TESTS:\runtime\test_type_error.py'. 960| assert no_slots not in result 961| assert use_slots not in result 962| 963| try: -->964| vars(f) ^^^^^^^ 965| except TypeError as e: f: defined in vars: UnboundLocalError ----------------- Missing both ~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_unbound_local_error.py", line 65, in test_Missing_both outer_missing_both() File "TESTS:\runtime\test_unbound_local_error.py", line 22, in outer_missing_both inner() File "TESTS:\runtime\test_unbound_local_error.py", line 21, in inner spam_missing_both += 1 UnboundLocalError: local variable 'spam_missing_both' referenced before assignment Did you forget to add either `global spam_missing_both` or `nonlocal spam_missing_both`? 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`. You're trying to use the name `spam_missing_both` identified by Python as being in the local scope of a function before having assigned it a value. The name `spam_missing_both` exists in both the global and nonlocal scope. This can be rather confusing and is not recommended. Depending on which variable you wanted to refer to, you needed to add either global spam_missing_both or nonlocal spam_missing_both as the first line inside your function. Execution stopped on line `65` of file 'TESTS:\runtime\test_unbound_local_error.py'. 63| def test_Missing_both(): 64| try: -->65| outer_missing_both() ^^^^^^^^^^^^^^^^^^^^ 66| except UnboundLocalError as e: global outer_missing_both: Exception raised on line `21` of file 'TESTS:\runtime\test_unbound_local_error.py'. 20| def inner(): -->21| spam_missing_both += 1 global spam_missing_both: 1 Missing global ~~~~~~~~~~~~~~ .. code-block:: none 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 10, 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`. You're trying to use the name `spam_missing_global` identified by Python as being in the local scope of a function before having assigned it a value. 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| def test_Missing_global(): 26| try: -->27| outer_missing_global() ^^^^^^^^^^^^^^^^^^^^^^ 28| except UnboundLocalError as e: global outer_missing_global: Exception raised on line `9` of file 'TESTS:\runtime\test_unbound_local_error.py'. 8| def inner(): -->9| spam_missing_global += 1 global spam_missing_global: 1 Missing nonlocal ~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_unbound_local_error.py", line 46, in test_Missing_nonlocal outer_missing_nonlocal() File "TESTS:\runtime\test_unbound_local_error.py", line 16, in outer_missing_nonlocal inner() File "TESTS:\runtime\test_unbound_local_error.py", line 15, 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`. You're trying to use the name `spam_missing_nonlocal` identified by Python as being in the local scope of a function before having assigned it a value. 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 `46` of file 'TESTS:\runtime\test_unbound_local_error.py'. 44| def test_Missing_nonlocal(): 45| try: -->46| outer_missing_nonlocal() ^^^^^^^^^^^^^^^^^^^^^^^^ 47| except UnboundLocalError as e: global outer_missing_nonlocal: Exception raised on line `15` of file 'TESTS:\runtime\test_unbound_local_error.py'. 14| def inner(): -->15| spam_missing_nonlocal += 1 Typo in local ~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_unbound_local_error.py", line 104, in test_Typo_in_local test2() File "TESTS:\runtime\test_unbound_local_error.py", line 101, in test2 alpha3 += 1 UnboundLocalError: local variable 'alpha3' referenced before assignment Did you mean `alpha1`? 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`. Instead of writing `alpha3`, perhaps you meant one of the following: * Local scope: `alpha1`, `alpha2` Execution stopped on line `104` of file 'TESTS:\runtime\test_unbound_local_error.py'. 100| alpha2 = 1 101| alpha3 += 1 102| 103| try: -->104| test2() ^^^^^^^ 105| except UnboundLocalError as e: test2: defined in Exception raised on line `101` of file 'TESTS:\runtime\test_unbound_local_error.py'. 98| def test2(): 99| alpha1 = 1 100| alpha2 = 1 -->101| alpha3 += 1 Using name of builtin ~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_unbound_local_error.py", line 125, in test_Using_name_of_builtin dist([]) File "TESTS:\runtime\test_unbound_local_error.py", line 121, in dist max = max(points) UnboundLocalError: local variable 'max' referenced before assignment 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`. `max` is a Python builtin function. You have tried to assign a value to `max` inside a function while also using its original meaning in the function. Note that it is generally not a good idea to give a local variable the same name as a Python builtin function (like `max`). Execution stopped on line `125` of file 'TESTS:\runtime\test_unbound_local_error.py'. 122| min = min(points) 123| return max - min 124| try: -->125| dist([]) ^^^^^^^^ 126| except UnboundLocalError as e: dist: defined in Exception raised on line `121` of file 'TESTS:\runtime\test_unbound_local_error.py'. 120| def dist(points): -->121| max = max(points) ^^^ 122| min = min(points) max: UnknownError ------------ Generic ~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_unknown_error.py", line 24, in test_Generic raise UnknownException("Some informative message about an unknown exception.") UnknownException: Some informative message about an unknown exception. An exception of type `UnknownException` is a subclass of `Exception`. Nothing more specific is known about `UnknownException`. All built-in exceptions defined by Python are derived from `Exception`. All user-defined exceptions should also be derived from this class. Exception raised on line `24` of file 'TESTS:\runtime\test_unknown_error.py'. 20| result = friendly_traceback.get_output() 21| assert "UnknownException -> Exception" in result 22| 23| try: -->24| raise UnknownException("Some informative message about an unknown exception.") 25| except Exception as e: global UnknownException: ValueError ---------- Convert to int ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 194, in test_Convert_to_int int('13a') ValueError: invalid literal for int() with base 10: '13a' A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. `'13a'` is an invalid argument for `int()` in base `10`. In base `10`, `int()` is most often use to convert a string containing the digits `0` to `9` into an integer. The following characters are not allowed: `a`. Exception raised on line `194` of file 'TESTS:\runtime\test_value_error.py'. 190| if english: 191| assert "needs to be first converted using `float()`" in result 192| 193| try: -->194| int('13a') ^^^^^^^^^^ 195| except ValueError as e: int: Could not convert to float ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 92, in test_Could_not_convert_to_float float("42b") ValueError: could not convert string to float: '42b' A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. The string `42b` cannot be converted to a `float` as it does not represent a number. Exception raised on line `92` of file 'TESTS:\runtime\test_value_error.py'. 90| def test_Could_not_convert_to_float(): 91| try: -->92| float("42b") ^^^^^^^^^^^^ 93| except ValueError as e: float: Date invalid month ~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 60, in test_Date_invalid_month d = date(2021, 13, 1) ValueError: month must be in 1..12 Did you specify an invalid month? A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. I am guessing that you specify an invalid value for a month in a `date` object. Valid values are integers, from 1 to 12. Exception raised on line `60` of file 'TESTS:\runtime\test_value_error.py'. 57| def test_Date_invalid_month(): 58| from datetime import date 59| try: -->60| d = date(2021, 13, 1) ^^^^^^^^^^^^^^^^^ 61| except ValueError as e: date: Not enough values to unpack ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none 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'. 24| assert "ValueError: not enough values to unpack (expected 3, got 2)" in result 25| 26| d = "ab" 27| try: -->28| a, b, c = d 29| except ValueError as e: d: 'ab' Pow third arg cannot be zero ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 108, in test_Pow_third_arg_cannot_be_zero pow(2, 4, a) ValueError: pow() 3rd argument cannot be 0 A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. The third argument of the function `pow()` cannot be zero. Exception raised on line `108` of file 'TESTS:\runtime\test_value_error.py'. 105| def test_Pow_third_arg_cannot_be_zero(): 106| a = 0 107| try: -->108| pow(2, 4, a) ^^^^^^^^^^^^ 109| except ValueError as e: a: 0 pow: Slots conflicts with class variable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 75, in test_Slots_conflicts_with_class_variable class F: ValueError: 'a' in __slots__ conflicts with class variable A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. The name `a` is used both as the name of a class variable and as a string item in the class `__slots__`; this is not allowed. Exception raised on line `75` of file 'TESTS:\runtime\test_value_error.py'. 73| def test_Slots_conflicts_with_class_variable(): 74| try: -->75| class F: 76| __slots__ = ["a", "b"] Too many values to unpack ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 44, 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 `44` of file 'TESTS:\runtime\test_value_error.py'. 41| def test_Too_many_values_to_unpack(): 42| c = [1, 2, 3] 43| try: -->44| a, b = c 45| except ValueError as e: c: [1, 2, 3] int base not in range ~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 209, in test_int_base_not_in_range int('18', base=37) ValueError: int() base must be >= 2 and <= 36, or 0 A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. The argument `base` of `int()` must be either zero or any integer from 2 to 36. You wrote 37 which is not allowed. Exception raised on line `209` of file 'TESTS:\runtime\test_value_error.py'. 207| def test_int_base_not_in_range(): 208| try: -->209| int('18', base=37) ^^^^^^^^^^^^^^^^^^ 210| except ValueError as e: int: remove item not in list ~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 236, in test_remove_item_not_in_list a_list.remove(b) ValueError: list.remove(x): x not in list A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. You have attempted to remove `b` from the list `a_list`. However, `a_list` does not contain `b`. Exception raised on line `236` of file 'TESTS:\runtime\test_value_error.py'. 233| a_list = [1, 2, 3] 234| b = 4 235| try: -->236| a_list.remove(b) ^^^^^^^^^^^^^^^^ 237| except ValueError as e: a_list: [1, 2, 3] b: 4 a_list.remove: time strptime incorrect format ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_value_error.py", line 133, in test_time_strptime_incorrect_format time.strptime("2020-01-01", "%d %m %Y") ValueError: time data '2020-01-01' does not match format '%d %m %Y' A `ValueError` indicates that a function or an operation received an argument of the right type, but an inappropriate value. The value you gave for the time is not in the format you specified. Make sure to use the same separator between items (for example, between day and month) and keep the order the same in both the data provided and the format you specified. The following table might be useful: https://docs.python.org/3/library/time.html#time.strftime The following site might also be useful: https://www.strfti.me/ Exception raised on line `133` of file 'TESTS:\runtime\test_value_error.py'. 129| return 130| 131| import time 132| try: -->133| time.strptime("2020-01-01", "%d %m %Y") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 134| except ValueError as e: time: time.strptime: ZeroDivisionError ----------------- Complex division ~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 180, 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 `180` of file 'TESTS:\runtime\test_zero_division_error.py'. 177| def test_Complex_division(): 178| zero = 0j 179| try: -->180| 1 / zero ^^^^^^^^ 181| except ZeroDivisionError as e: zero: 0j Division by zero literal ~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 229, in test_Division_by_zero_literal 1.0 / 0 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 zero. Exception raised on line `229` of file 'TESTS:\runtime\test_zero_division_error.py'. 225| if friendly_traceback.get_lang() == "en": 226| assert "Using the modulo operator, `%`, you are dividing by zero" in result 227| 228| try: -->229| 1.0 / 0 ^^^^^^^ 230| except ZeroDivisionError as e: Division operator ~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 20, 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 `20` of file 'TESTS:\runtime\test_zero_division_error.py'. 13| if friendly_traceback.get_lang() == "en": 14| assert ( 15| "The following mathematical expression includes a division by zero" 16| in result 17| ) 18| 19| try: -->20| 1 / zero ^^^^^^^^ 21| except ZeroDivisionError as e: zero: 0 Divmod ~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 100, 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 `100` of file 'TESTS:\runtime\test_zero_division_error.py'. 97| def test_Divmod(): 98| zero = 0 99| try: -->100| divmod(1, zero) ^^^^^^^^^^^^^^^ 101| except ZeroDivisionError as e: zero: 0 divmod: Float division ~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 148, 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 `148` of file 'TESTS:\runtime\test_zero_division_error.py'. 145| def test_Float_division(): 146| zero = 0.0 147| try: -->148| 1 / zero ^^^^^^^^ 149| except ZeroDivisionError as e: zero: 0.0 Float divmod ~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 164, in test_Float_divmod divmod(1, zero) ZeroDivisionError: float divmod() 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 equal to zero. Exception raised on line `164` of file 'TESTS:\runtime\test_zero_division_error.py'. 161| def test_Float_divmod(): 162| zero = 0.0 163| try: -->164| divmod(1, zero) ^^^^^^^^^^^^^^^ 165| except ZeroDivisionError as e: zero: 0.0 divmod: Float modulo ~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 132, 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 `132` of file 'TESTS:\runtime\test_zero_division_error.py'. 125| assert ( 126| "The following mathematical expression includes a division by zero" 127| in result 128| ) 129| assert "done using the modulo operator" in result 130| 131| try: -->132| 1 % zero ^^^^^^^^ 133| except ZeroDivisionError as e: zero: 0.0 Integer division operator ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 49, 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 `49` of file 'TESTS:\runtime\test_zero_division_error.py'. 42| if friendly_traceback.get_lang() == "en": 43| assert ( 44| "The following mathematical expression includes a division by zero" 45| in result 46| ) 47| 48| try: -->49| 1 // zero ^^^^^^^^^ 50| except ZeroDivisionError as e: zero: 0 Mixed operations ~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 243, in test_Mixed_operations a = divmod(8, 1 // 2) 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 following mathematical expression includes a division by zero: divmod(8, 1 // 2) Exception raised on line `243` of file 'TESTS:\runtime\test_zero_division_error.py'. 241| def test_Mixed_operations(): 242| try: -->243| a = divmod(8, 1 // 2) ^^^^^^^^^^^^^^^^^ 244| except ZeroDivisionError as e: divmod: 1 // 2: 0 Modulo operator ~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 81, 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 `81` of file 'TESTS:\runtime\test_zero_division_error.py'. 74| if friendly_traceback.get_lang() == "en": 75| assert ( 76| "The following mathematical expression includes a division by zero" 77| in result 78| ) 79| 80| try: -->81| 1 % zero ^^^^^^^^ 82| except ZeroDivisionError as e: zero: 0 Raise zero negative power ~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: none Traceback (most recent call last): File "TESTS:\runtime\test_zero_division_error.py", line 196, 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 `196` of file 'TESTS:\runtime\test_zero_division_error.py'. 193| def test_Raise_zero_negative_power(): 194| zero = 0 195| try: -->196| zero**-1 ^^^^^^^^ 197| except ZeroDivisionError as e: zero: 0