'python package for c traceback for error in python file

When I want to see the code for how something is implemented in cpython, I need to manually search for it, for example, when multiplying a set by 2,

s = {1, 2, 3, 1}
s * 2

gives the error,

TypeError: unsupported operand type(s) for *: 'set' and 'int'

to find the implementation of this in cpython, I had to manually search and then found this line,

https://github.com/python/cpython/blob/28890427c58d30f1041b36859733159475c67496/Objects/setobject.c#L2092

which probably is the reason for there being no multiply for set, as there is no set_mul.

but I had to manually search for this.

another example is this one,

(1.__add__)

which gives the error,

SyntaxError: invalid decimal literal

but to find where is this thing implemented in cpython I again need to manually search.

If I get an error for something like inspect module in the cpython repository, then I can use shortcut in my IDE to navigate to the reasoning for that error, because inspect module is written in python in the cpython repository, so it is easier for me to navigate/find the reason for an error. like,

import inspect
inspect.getsource(len)

gives error,

TypeError: module, class, method, function, traceback, frame, or code object was expected, got builtin_function_or_method

which I am able to locate through the traceback in the IDE that is here,

https://github.com/python/cpython/blob/28890427c58d30f1041b36859733159475c67496/Lib/inspect.py#L919

but for things implemented in c in cpython repository, I need to manually search.

Is there a repository/tool which enables to search for the traceback for a c file error in cpython repository?



Solution 1:[1]

Don't use

s = {1, 2, 3, 1}
s * 2

use

s = [1, 2, 3, 1]
s * 2

{} is dict and dict dont have * operations. If you use the dict, you should have a key.

Example:

s = {"first": 1, "second": 2, "third": 3, "fourth": 1}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user438383