Skip to content

fix: Skip 'could not read code' errors for special methods #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/pytkdocs/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ def get_module_documentation(self, node: ObjectNode, select_members=None) -> Mod
try:
code = Path(node.file_path).read_text()
except (OSError, UnicodeDecodeError):
self.errors.append(f"Couldn't read source for '{path}': {error}")
source = None
else:
source = Source(code, 1) if code else None
Expand Down Expand Up @@ -628,13 +627,11 @@ def get_function_documentation(self, node: ObjectNode) -> Function:
try:
signature = inspect.signature(function)
except TypeError as error:
self.errors.append(f"Couldn't get signature for '{path}': {error}")
signature = None

try:
source = Source(*inspect.getsourcelines(function))
except OSError as error:
self.errors.append(f"Couldn't read source for '{path}': {error}")
source = None

properties: List[str] = []
Expand Down Expand Up @@ -677,15 +674,13 @@ def get_property_documentation(self, node: ObjectNode) -> Attribute:
try:
signature = inspect.signature(sig_source_func)
except (TypeError, ValueError) as error:
self.errors.append(f"Couldn't get signature for '{path}': {error}")
attr_type = None
else:
attr_type = signature.return_annotation

try:
source = Source(*inspect.getsourcelines(sig_source_func))
except (OSError, TypeError) as error:
self.errors.append(f"Couldn't get source for '{path}': {error}")
source = None

return Attribute(
Expand Down Expand Up @@ -879,7 +874,6 @@ def get_method_documentation(self, node: ObjectNode, properties: Optional[List[s
try:
source = Source(*inspect.getsourcelines(method))
except OSError as error:
self.errors.append(f"Couldn't read source for '{path}': {error}")
source = None
except TypeError:
source = None
Expand All @@ -898,7 +892,6 @@ def get_method_documentation(self, node: ObjectNode, properties: Optional[List[s
# raise a ValueError().
signature = inspect.signature(method)
except ValueError as error:
self.errors.append(f"Couldn't read signature for '{path}': {error}")
signature = None

return Method(
Expand Down
11 changes: 1 addition & 10 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,7 @@ def test_inheriting_typing_NamedTuple():
"""
loader = Loader()
loader.get_object_documentation("tests.fixtures.inheriting_typing_NamedTuple")

if sys.version_info > (3, 7, 99):
assert len(loader.errors) == 1
else:
# there are 4 class-attributes, 2 errors (source, signature) per attribute
assert len(loader.errors) >= 8
for error in loader.errors[-8:]:
assert "itemgetter" in error
for error in loader.errors[:-8]:
assert "could not get source code" in error
assert len(loader.errors) == 0


def test_nested_class():
Expand Down