Skip to content

Commit

Permalink
Merge pull request #24 from explosion/fix/registry-find-cython
Browse files Browse the repository at this point in the history
Work around Cython issue in registry.find
  • Loading branch information
ines committed Aug 21, 2021
2 parents dbae343 + b84c864 commit 3dc5259
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions catalogue/__init__.py
Expand Up @@ -146,12 +146,19 @@ def find(self, name: str) -> Dict[str, Optional[Union[str, int]]]:
RETURNS (Dict[str, Optional[Union[str, int]]]): The function info.
"""
func = self.get(name)
_, line_no = inspect.getsourcelines(func)
module = inspect.getmodule(func)
# These calls will fail for Cython modules so we need to work around them
line_no: Optional[int] = None
file_name: Optional[str] = None
try:
_, line_no = inspect.getsourcelines(func)
file_name = inspect.getfile(func)
except (TypeError, ValueError):
pass
docstring = inspect.getdoc(func)
return {
"module": module.__name__ if module else None,
"file": inspect.getfile(func),
"file": file_name,
"line_no": line_no,
"docstring": inspect.cleandoc(docstring) if docstring else None,
}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,5 +1,5 @@
[metadata]
version = 2.0.5
version = 2.0.6
description = Super lightweight function registries for your library
url = https://github.com/explosion/catalogue
author = Explosion
Expand Down

0 comments on commit 3dc5259

Please sign in to comment.