Skip to content

Commit

Permalink
Raise error in case inspect.get_source is not supported (#9068)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusty1s committed Mar 18, 2024
1 parent a1a3724 commit ae7ce43
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions torch_geometric/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,14 @@ def collect_param_data(

def get_source(self, cls: Optional[Type] = None) -> str:
r"""Returns the source code of :obj:`cls`."""
from torch_geometric.nn import MessagePassing

cls = cls or self._cls
if cls.__name__ in self._source_dict:
return self._source_dict[cls.__name__]
try:
source = inspect.getsource(cls)
except Exception:
source = ''
if cls in {object, torch.nn.Module, MessagePassing}:
return ''
source = inspect.getsource(cls)
self._source_dict[cls.__name__] = source
return source

Expand Down

0 comments on commit ae7ce43

Please sign in to comment.