Skip to content
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

feat: Add type hints to rdflib.graph #2080

Merged
merged 1 commit into from
Aug 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ and will be removed for release.
<!-- -->

- Added type hints.
[PR #2057](https://github.com/RDFLib/rdflib/pull/2057).
- `rdflib.store` and builtin stores have mostly complete type hints.
[PR #2057](https://github.com/RDFLib/rdflib/pull/2057).
- `rdflib.graph` have mostly complete type hints.
[PR #2080](https://github.com/RDFLib/rdflib/pull/2080).

<!-- -->
<!-- -->
Expand Down
22 changes: 15 additions & 7 deletions devtools/diffrtpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@
from strip_hints import strip_string_to_string


def clean_python(code: str) -> str:
code = strip_string_to_string(code, to_empty=True, strip_nl=True)
def clean_python(input: Path) -> str:
code = input.read_text()
try:
code = strip_string_to_string(code, to_empty=True, strip_nl=True)
except Exception:
logging.warning(
"failed to strip type hints from %s, falling back to using with type hints",
input,
)
code = code
code = python_minifier.minify(
code,
remove_annotations=True,
Expand Down Expand Up @@ -106,12 +114,12 @@ def handle(self, parse_result: argparse.Namespace) -> None:
"base = %s, lhs_file = %s, rhs_file = %s", base, lhs_file, rhs_file
)

lhs_file_content = lhs_file.read_text()
rhs_file_content = rhs_file.read_text()

if lhs_file.name.endswith(".py") and rhs_file.name.endswith(".py"):
lhs_file_content = clean_python(lhs_file_content)
rhs_file_content = clean_python(rhs_file_content)
lhs_file_content = clean_python(lhs_file)
rhs_file_content = clean_python(rhs_file)
else:
lhs_file_content = lhs_file.read_text()
rhs_file_content = rhs_file.read_text()

lhs_file_lines = lhs_file_content.splitlines(keepends=True)
rhs_file_lines = rhs_file_content.splitlines(keepends=True)
Expand Down
19 changes: 15 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def find_version(filename):
("py:class", "importlib.metadata.EntryPoint"),
("py:class", "xml.dom.minidom.Document"),
("py:class", "xml.dom.minidom.DocumentFragment"),
("py:class", "isodate.duration.Duration"),
# sphinx-autodoc-typehints has some issues with TypeVars.
# https://github.com/tox-dev/sphinx-autodoc-typehints/issues/39
("py:class", "rdflib.plugin.PluginT"),
Expand All @@ -282,13 +283,23 @@ def find_version(filename):
if sys.version_info < (3, 9):
nitpick_ignore.extend(
[
("py:class", "_TriplePatternType"),
("py:class", "_TripleType"),
("py:class", "_ContextIdentifierType"),
("py:class", "_ContextType"),
("py:class", "_GraphT"),
("py:class", "_NamespaceSetString"),
("py:class", "_ObjectType"),
("py:class", "_PredicateType"),
("py:class", "_QuadSelectorType"),
("py:class", "_SubjectType"),
("py:class", "_ContextType"),
("py:class", "_ContextIdentifierType"),
("py:class", "_TripleOrPathTripleType"),
("py:class", "_TripleOrQuadPathPatternType"),
("py:class", "_TripleOrQuadPatternType"),
("py:class", "_TriplePathPatternType"),
("py:class", "_TriplePathType"),
("py:class", "_TriplePatternType"),
("py:class", "_TripleSelectorType"),
("py:class", "_TripleType"),
("py:class", "_TripleOrTriplePathType"),
("py:class", "TextIO"),
]
)
Expand Down