diff options
| author | Iwan Aucamp <aucampia@gmail.com> | 2022-08-23 19:39:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-23 19:39:18 +0200 |
| commit | 256e9a2d2bf9800d1e29f03e22b0ac324d28119c (patch) | |
| tree | aef346c79dcbabf431432001dc797556e1492d5d /devtools/diffrtpy.py | |
| parent | a70a9c82649f9345c3691d69df6f1108e9e05871 (diff) | |
| download | rdflib-256e9a2d2bf9800d1e29f03e22b0ac324d28119c.tar.gz | |
feat: Add type hints to rdflib.graph (#2080)
More or less complete type hints for the rdflib.graph module.
Other changes:
- Improved/simplified type hints in `rdflib.store` and store plugins.
- Add type ignores for various type errors that occur with the type
hints.
This is split-off from <https://github.com/RDFLib/rdflib/pull/1850>.
This PR does not change runtime behaviour.
Diffstat (limited to 'devtools/diffrtpy.py')
| -rwxr-xr-x | devtools/diffrtpy.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/devtools/diffrtpy.py b/devtools/diffrtpy.py index 3c2c766f..d8873aa5 100755 --- a/devtools/diffrtpy.py +++ b/devtools/diffrtpy.py @@ -32,8 +32,16 @@ import python_minifier 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, @@ -106,12 +114,12 @@ class Application: "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) |
