nvdv / vprof

Visual profiler for Python
BSD 2-Clause "Simplified" License
3.95k stars 154 forks source link

Prevent crash on unexpected type repr #73

Closed evhub closed 6 years ago

evhub commented 6 years ago

For arbitrary types, repr(type(obj)) is not guaranteed to be of any particular form. Thus, you can't assume that the regex will match something, and therefore the match[0] call needs to be put under a check to make sure that match actually contains something first.

As an example of a type repr that doesn't conform to what you are expecting in the standard library:

from typing import TypeVar
x = TypeVar("x")
print(type(x))  # prints "typing.TypeVar"
nvdv commented 6 years ago

Awesome, thanks!