Skip to content

Commit

Permalink
BUG: add support for inspecting built-in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed May 16, 2024
1 parent 8efd0f7 commit eecbf3b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/wxc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ def get_sourcefile(obj):
# this happens for instance with `math.sqrt`
# because inspect.getfile doesn't work on compiled code
# the second condition is met for os.fspath
if inspect.ismodule(obj) or is_builtin_func(obj):
raise
if isinstance(obj, property):
if (
inspect.ismodule(obj)
or is_builtin_func(obj)
or inspect.getmodule(obj) is builtins
or isinstance(obj, property)
):
raise
return get_sourcefile(inspect.getmodule(obj))
return file
Expand Down Expand Up @@ -164,11 +167,15 @@ def get_full_data(name: str) -> dict:
source = get_sourcefile(obj)
except RecursionError:
pass
except TypeError:
# as of Python 3.11, inspect.getfile doesn't have support for properties
# but we're not making this a hard failure in case it is added in the future
# and we fallback to finding out the sourcefile of the class itself
if isinstance(obj, property):
except TypeError as exc:
if "built-in module" in str(exc):
# see https://github.com/neutrinoceros/wxc/issues/233
data["source"] = "built-in"
break
elif isinstance(obj, property):
# as of Python 3.11, inspect.getfile doesn't have support for properties
# but we're not making this a hard failure in case it is added in the future
# and we fallback to finding out the sourcefile of the class itself
continue
else:
raise
Expand Down

0 comments on commit eecbf3b

Please sign in to comment.