Skip to content

Commit

Permalink
New sphinx docs fix (#2852)
Browse files Browse the repository at this point in the history
* Fix typo, ConjunctionGraph -> ConjunctiveGraph, the new version of Sphinx-autodocs flagged this as an error.

* more autodoc fixes for new sphinx version

* Fix sphinx autodocs complaining while probing attributes on DefinedNamespace classes.
Add correct annotation details for items that sphinx cannot find.

---------

Co-authored-by: Nicholas Car <[email protected]>
  • Loading branch information
ashleysommer and nicholascar authored Jul 25, 2024
1 parent b35fd19 commit bb17072
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ setuptools = ">=68,<72"
wheel = ">=0.42,<0.44"

[tool.poetry.group.docs.dependencies]
sphinx = "^7.1.1"
sphinx = ">=7.1.2,<8"
myst-parser = ">=2,<4"
sphinxcontrib-apidoc = ">=0.3,<0.6"
sphinx-autodoc-typehints = "^1.17.1"
sphinx-autodoc-typehints = ">=1.25.3,<=2.0.1"
typing-extensions = "^4.5.0"

[tool.poetry.group.lint.dependencies]
Expand Down
27 changes: 18 additions & 9 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ class Graph(Node):
For more on named graphs, see: http://www.w3.org/2004/03/trix/
"""

context_aware: bool
formula_aware: bool
default_union: bool
base: Optional[str]

def __init__(
self,
store: Union[Store, str] = "default",
Expand Down Expand Up @@ -1393,9 +1398,9 @@ def parse(
:doc:`Security Considerations </security_considerations>`
documentation.
:param source: An `InputSource`, file-like object, `Path` like object,
or string. In the case of a string the string is the location of the
source.
:param source: An `xml.sax.xmlreader.InputSource`, file-like object,
`pathlib.Path` like object, or string. In the case of a string the string
is the location of the source.
:param location: A string indicating the relative or absolute URL of the
source. `Graph`'s absolutize method is used if a relative location
is specified.
Expand Down Expand Up @@ -1910,6 +1915,8 @@ class ConjunctiveGraph(Graph):
All queries are carried out against the union of all graphs.
"""

default_context: _ContextType

def __init__(
self,
store: Union[Store, str] = "default",
Expand Down Expand Up @@ -2227,8 +2234,9 @@ def parse(
See :meth:`rdflib.graph.Graph.parse` for documentation on arguments.
If the source is in a format that does not support named graphs it's triples
will be added to the default graph (i.e. `Dataset.default_context`).
If the source is in a format that does not support named graphs its triples
will be added to the default graph
(i.e. :attr:`ConjunctiveGraph.default_context`).
:Returns:
Expand All @@ -2254,7 +2262,7 @@ def parse(
the ``publicID`` parameter will also not be used as the name for the
graph that the data is loaded into, and instead the triples from sources
that do not support named graphs will be loaded into the default graph
(i.e. `ConjunctiveGraph.default_context`).
(i.e. :attr:`ConjunctiveGraph.default_context`).
"""

source = create_input_source(
Expand Down Expand Up @@ -2488,8 +2496,9 @@ def parse(
The source is specified using one of source, location, file or data.
If the source is in a format that does not support named graphs it's triples
will be added to the default graph (i.e. `Dataset.default_context`).
If the source is in a format that does not support named graphs its triples
will be added to the default graph
(i.e. :attr:`.Dataset.default_context`).
.. caution::
Expand All @@ -2510,7 +2519,7 @@ def parse(
the ``publicID`` parameter will also not be used as the name for the
graph that the data is loaded into, and instead the triples from sources
that do not support named graphs will be loaded into the default graph
(i.e. `ConjunctiveGraph.default_context`).
(i.e. :attr:`.Dataset.default_context`).
"""

c = ConjunctiveGraph.parse(
Expand Down
2 changes: 1 addition & 1 deletion rdflib/namespace/_WGS.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class WGS(DefinedNamespace):
Basic Geo (WGS84 lat/long) Vocabulary
The HTML Specification for the vocabulary can be found
`here <https://www.w3.org/2003/01/geo/>`.
here <https://www.w3.org/2003/01/geo/>.
"""

_NS = Namespace("https://www.w3.org/2003/01/geo/wgs84_pos#")
Expand Down
12 changes: 12 additions & 0 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ def __repr__(self) -> str:
"_underscore_num",
}

# Some libraries probe classes for certain attributes or items.
# This is a list of those attributes and items that should be ignored.
_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
}


class DefinedNamespaceMeta(type):
"""Utility metaclass for generating URIRefs with a common prefix."""
Expand All @@ -246,10 +253,13 @@ class DefinedNamespaceMeta(type):
@lru_cache(maxsize=None)
def __getitem__(cls, name: str, default=None) -> URIRef:
name = str(name)

if name in _DFNS_RESERVED_ATTRS:
raise AttributeError(
f"DefinedNamespace like object has no attribute {name!r}"
)
elif name in _IGNORED_ATTR_LOOKUP:
raise KeyError()
if str(name).startswith("__"):
# NOTE on type ignore: This seems to be a real bug, super() does not
# implement this method, it will fail if it is ever reached.
Expand All @@ -265,6 +275,8 @@ def __getitem__(cls, name: str, default=None) -> URIRef:
return cls._NS[name]

def __getattr__(cls, name: str):
if name in _IGNORED_ATTR_LOOKUP:
raise AttributeError()
return cls.__getitem__(name)

def __repr__(cls) -> str:
Expand Down

0 comments on commit bb17072

Please sign in to comment.