Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: DefinedNamespace: always raise AttributeError for
_partialmethod
This patch changes `DefinedNamespace` to always raise `AttributeError` if `_partialmethod` is not defined, even if `DefinedNamespace._fail == False`. This because this property is accessed by `inspect.signature` when building docs and if `AttributeError` is not raised when this property is accessed it results in infinite recursion. ``` WARNING: error while formatting signature for rdflib.namespace.DefinedNamespace: Handler <function record_typehints at 0x7fbf2696dd40> for event 'autodoc-process-signature' threw an exception (exception: maximum recursion depth exceeded while calling a Python object) ```
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from rdflib import BRICK | ||
|
||
NOFAIL_DEFINED_NAMESPACE = BRICK | ||
|
||
|
||
def test_nofail_attr() -> None: | ||
""" | ||
Undefined attributes do not raise an exception if `DefinedNamespace._fail` | ||
is `False`. | ||
""" | ||
assert not NOFAIL_DEFINED_NAMESPACE._fail | ||
assert f"{NOFAIL_DEFINED_NAMESPACE}not_defined_in_namespace" == f"{NOFAIL_DEFINED_NAMESPACE.not_defined_in_namespace}" | ||
|
||
|
||
def test_nofail_partialmethod_attrerror() -> None: | ||
""" | ||
Accessing `_partialmethod` raises an exception even if | ||
`DefinedNamespace._fail` is `False`. | ||
""" | ||
assert not NOFAIL_DEFINED_NAMESPACE._fail | ||
with pytest.raises(AttributeError): | ||
_ = NOFAIL_DEFINED_NAMESPACE._partialmethod |