Skip to content

Commit 7df77cd

Browse files
authored
fix: correct imports and __all__ (#2340)
Disable [`implicit_reexport`](https://mypy.readthedocs.io/en/stable/config_file.html#confval-implicit_reexport) and eliminate all errors reported by mypy after this. This helps ensure that import statements import from the right module and that the `__all__` variable is correct.
1 parent 81d13d4 commit 7df77cd

25 files changed

+143
-72
lines changed

docs/conf.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import os
1717
import re
1818
import sys
19+
from typing import Any, Dict
1920

2021
import sphinx
22+
import sphinx.application
2123

2224
import rdflib
2325

@@ -47,6 +49,7 @@
4749
"sphinx.ext.autosectionlabel",
4850
]
4951

52+
# https://github.com/sphinx-contrib/apidoc/blob/master/README.rst#configuration
5053
apidoc_module_dir = "../rdflib"
5154
apidoc_output_dir = "apidocs"
5255

@@ -328,3 +331,50 @@ def find_version(filename):
328331

329332
if sys.version_info < (3, 8):
330333
nitpick_ignore.extend([("py:class", "importlib_metadata.EntryPoint")])
334+
335+
336+
def autodoc_skip_member_handler(
337+
app: sphinx.application.Sphinx,
338+
what: str,
339+
name: str,
340+
obj: Any,
341+
skip: bool,
342+
options: Dict[str, Any],
343+
):
344+
"""
345+
This function will be called by Sphinx when it is deciding whether to skip a
346+
member of a class or module.
347+
"""
348+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#event-autodoc-skip-member
349+
if (
350+
app.env.docname == "apidocs/rdflib"
351+
and what == "module"
352+
and type(obj).__name__.endswith("DefinedNamespaceMeta")
353+
):
354+
# Don't document namespaces in the `rdflib` module, they will be
355+
# documented in the `rdflib.namespace` module instead and Sphinx does
356+
# not like when these are documented in two places.
357+
#
358+
# An example of the WARNINGS that occur without this is:
359+
#
360+
# "WARNING: duplicate object description of rdflib.namespace._SDO.SDO,
361+
# other instance in apidocs/rdflib, use :noindex: for one of them"
362+
logging.info(
363+
"Skipping %s %s in %s, it will be documented in ",
364+
what,
365+
name,
366+
app.env.docname,
367+
)
368+
return True
369+
return None
370+
371+
372+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#skipping-members
373+
def setup(app: sphinx.application.Sphinx) -> None:
374+
"""
375+
Setup the Sphinx application.
376+
"""
377+
378+
# Register a autodoc-skip-member handler so that certain members can be
379+
# skipped.
380+
app.connect("autodoc-skip-member", autodoc_skip_member_handler)

docs/rdf_terms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Common XSD datatypes
150150
^^^^^^^^^^^^^^^^^^^^
151151
152152
Most simple literals such as *string* or *integer* have XML Schema (XSD) datatypes defined for them, see the figure
153-
below. Additionally, these XSD datatypes are listed in the :class:`XSD Namespace class <rdflib.XSD>` that
153+
below. Additionally, these XSD datatypes are listed in the :class:`XSD Namespace class <rdflib.namespace.XSD>` that
154154
ships with RDFLib, so many Python code editors will prompt you with autocomplete for them when using it.
155155
156156
Remember, you don't *have* to use XSD datatypes and can always make up your own, as GeoSPARQL does, as described above.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ disallow_subclassing_any = false
211211
warn_unreachable = true
212212
warn_unused_ignores = true
213213
no_implicit_optional = false
214+
implicit_reexport = false
214215

215216
[[tool.mypy.overrides]]
216217
module = "pyparsing.*"

rdflib/namespace/_GEO.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ class GEO(DefinedNamespace):
99
Generated from: http://schemas.opengis.net/geosparql/1.0/geosparql_vocab_all.rdf
1010
Date: 2021-12-27 17:38:15.101187
1111
12-
<http://www.opengis.net/ont/geosparql> dc:creator "Open Geospatial Consortium"^^xsd:string
13-
dc:date "2012-04-30"^^xsd:date
14-
dc:source <http://www.opengis.net/doc/IS/geosparql/1.0>
15-
"OGC GeoSPARQL – A Geographic Query Language for RDF Data OGC 11-052r5"^^xsd:string
16-
rdfs:seeAlso <http://www.opengis.net/def/function/ogc-geosparql/1.0>
17-
<http://www.opengis.net/def/rule/ogc-geosparql/1.0>
18-
<http://www.opengis.net/doc/IS/geosparql/1.0>
19-
owl:imports dc:
20-
<http://www.opengis.net/ont/gml>
21-
<http://www.opengis.net/ont/sf>
22-
<http://www.w3.org/2004/02/skos/core>
23-
owl:versionInfo "OGC GeoSPARQL 1.0"^^xsd:string
12+
.. code-block:: Turtle
13+
14+
<http://www.opengis.net/ont/geosparql> dc:creator "Open Geospatial Consortium"^^xsd:string
15+
dc:date "2012-04-30"^^xsd:date
16+
dc:source <http://www.opengis.net/doc/IS/geosparql/1.0>
17+
"OGC GeoSPARQL – A Geographic Query Language for RDF Data OGC 11-052r5"^^xsd:string
18+
rdfs:seeAlso <http://www.opengis.net/def/function/ogc-geosparql/1.0>
19+
<http://www.opengis.net/def/rule/ogc-geosparql/1.0>
20+
<http://www.opengis.net/doc/IS/geosparql/1.0>
21+
owl:imports dc:
22+
<http://www.opengis.net/ont/gml>
23+
<http://www.opengis.net/ont/sf>
24+
<http://www.w3.org/2004/02/skos/core>
25+
owl:versionInfo "OGC GeoSPARQL 1.0"^^xsd:string
2426
"""
2527

2628
# http://www.w3.org/2000/01/rdf-schema#Datatype

rdflib/namespace/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,34 @@
9191
"ClosedNamespace",
9292
"DefinedNamespace",
9393
"NamespaceManager",
94+
"BRICK",
95+
"CSVW",
96+
"DC",
97+
"DCAM",
98+
"DCAT",
99+
"DCMITYPE",
100+
"DCTERMS",
101+
"DOAP",
102+
"FOAF",
103+
"GEO",
104+
"ODRL2",
105+
"ORG",
106+
"OWL",
107+
"PROF",
108+
"PROV",
109+
"QB",
110+
"RDF",
111+
"RDFS",
112+
"SDO",
113+
"SH",
114+
"SKOS",
115+
"SOSA",
116+
"SSN",
117+
"TIME",
118+
"VANN",
119+
"VOID",
120+
"WGS",
121+
"XSD",
94122
]
95123

96124
logger = logging.getLogger(__name__)

rdflib/plugins/stores/sparqlconnector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,6 @@ def update(
185185
self.update_endpoint + qsa, data=query.encode(), headers=args["headers"]
186186
)
187187
)
188+
189+
190+
__all__ = ["SPARQLConnector", "SPARQLConnectorException"]

rdflib/plugins/stores/sparqlstore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,3 +1011,6 @@ def predicate_objects(
10111011
"""A generator of (predicate, object) tuples for the given subject"""
10121012
for t, c in self.triples((subject, None, None)):
10131013
yield t[1], t[2]
1014+
1015+
1016+
__all__ = ["SPARQLUpdateStore", "SPARQLStore"]

test/jsonld/runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# -*- coding: UTF-8 -*-
22
import json
33

4-
from rdflib import ConjunctiveGraph
4+
from rdflib import BNode, ConjunctiveGraph
55
from rdflib.compare import isomorphic
66
from rdflib.parser import InputSource
77
from rdflib.plugins.parsers.jsonld import JsonLDParser, to_rdf
88

99
# monkey-patch N-Quads parser via it's underlying W3CNTriplesParser to keep source bnode id:s ..
10-
from rdflib.plugins.parsers.ntriples import W3CNTriplesParser, bNode, r_nodeid
10+
from rdflib.plugins.parsers.ntriples import W3CNTriplesParser, r_nodeid
1111
from rdflib.plugins.serializers.jsonld import from_rdf
1212
from rdflib.plugins.shared.jsonld.keys import CONTEXT, GRAPH
1313

1414

1515
def _preserving_nodeid(self, bnode_context=None):
1616
if not self.peek("_"):
1717
return False
18-
return bNode(self.eat(r_nodeid).group(1))
18+
return BNode(self.eat(r_nodeid).group(1))
1919

2020

2121
DEFAULT_PARSER_VERSION = 1.0

test/jsonld/test_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: UTF-8 -*-
2-
from rdflib.plugin import Parser, Serializer, register
2+
from rdflib.parser import Parser
3+
from rdflib.plugin import register
4+
from rdflib.serializer import Serializer
35

46
register("json-ld", Parser, "rdflib.plugins.parsers.jsonld", "JsonLDParser")
57
register("json-ld", Serializer, "rdflib.plugins.serializers.jsonld", "JsonLDSerializer")

test/jsonld/test_compaction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import pytest
88

99
from rdflib import Graph
10-
from rdflib.plugin import Serializer, register
10+
from rdflib.plugin import register
11+
from rdflib.serializer import Serializer
1112

1213
register("json-ld", Serializer, "rdflib.plugins.serializers.jsonld", "JsonLDSerializer")
1314

0 commit comments

Comments
 (0)