Skip to content

Commit

Permalink
better handling for any/all double-underscore properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysommer committed Nov 1, 2024
1 parent c843fe1 commit 9578547
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ def __repr__(self) -> str:
_IGNORED_ATTR_LOOKUP: Set[str] = {
"_pytestfixturefunction", # pytest tries to look this up on Defined namespaces
"_partialmethod", # sphinx tries to look this up during autodoc generation
"__test__", # pytest checks for this old nose-test style constant
"__signature__", # inspect.signature returns this, it cannot be used
}


class DefinedNamespaceMeta(type):
"""Utility metaclass for generating URIRefs with a common prefix."""

__slots__: Tuple[str, ...] = tuple()

_NS: Namespace
_warn: bool = True
_fail: bool = False # True means mimic ClosedNamespace
Expand Down Expand Up @@ -279,6 +279,8 @@ def __getattr__(cls, name: str):
raise AttributeError(
f"DefinedNamespace like object has no attribute {name!r}"
)
elif name.startswith("__"):
return super(DefinedNamespaceMeta, cls).__getattribute__(name)
return cls.__getitem__(name)

def __repr__(cls) -> str:
Expand Down Expand Up @@ -322,7 +324,7 @@ def __dir__(cls) -> Iterable[str]:
return values

def as_jsonld_context(self, pfx: str) -> dict: # noqa: N804
"""Returns this DefinedNamespace as a a JSON-LD 'context' object"""
"""Returns this DefinedNamespace as a JSON-LD 'context' object"""
terms = {pfx: str(self._NS)}
for key, term in self.__annotations__.items():
if issubclass(term, URIRef):
Expand All @@ -337,6 +339,8 @@ class DefinedNamespace(metaclass=DefinedNamespaceMeta):
Warnings are emitted if unknown members are referenced if _warn is True
"""

__slots__: Tuple[str, ...] = tuple()

def __init__(self):
raise TypeError("namespace may not be instantiated")

Expand Down

0 comments on commit 9578547

Please sign in to comment.