Skip to content

Commit 43ff130

Browse files
committed
Add type signatures to most of case_utils
Some further signature work will come to case_file. References: * [AC-211] Add static type checking to CASE-Utilities-Python Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 97616b4 commit 43ff130

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

case_utils/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313

1414
__version__ = "0.2.1"
1515

16+
import typing
1617
import warnings
1718

1819
import rdflib.util # type: ignore
1920

2021
from . import local_uuid
2122

22-
def guess_format(fpath, fmap=None):
23+
def guess_format(
24+
fpath : str,
25+
fmap : typing.Optional[typing.Dict[str, str]] = None
26+
) -> typing.Optional[str]:
2327
warnings.warn("The functionality in case_utils.guess_format is now upstream. Please revise your code to use rdflib.util.guess_format. The function arguments remain the same. case_utils.guess_format will be removed in case_utils 0.4.0.", DeprecationWarning)
2428

2529
return rdflib.util.guess_format(fpath, fmap)

case_utils/case_file/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import datetime
2121
import hashlib
2222
import os
23+
import typing
2324

2425
import rdflib # type: ignore
2526

@@ -234,7 +235,7 @@ def main() -> None:
234235
else:
235236
output_format = args.output_format
236237

237-
serialize_kwargs = {
238+
serialize_kwargs : typing.Dict[str, typing.Any] = {
238239
"format": output_format
239240
}
240241
if output_format == "json-ld":

case_utils/case_sparql_construct/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import argparse
2121
import os
2222
import logging
23+
import typing
2324

2425
import rdflib.plugins.sparql # type: ignore
2526

@@ -74,7 +75,7 @@ def main() -> None:
7475
else:
7576
output_format = args.output_format
7677

77-
serialize_kwargs = {
78+
serialize_kwargs : typing.Dict[str, typing.Any] = {
7879
"format": output_format
7980
}
8081
if output_format == "json-ld":

case_utils/local_uuid.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
import sys
2222
import uuid
2323

24-
USE_DEMO_UUID = False
24+
USE_DEMO_UUID : bool = False
2525

26-
DEMO_UUID_COUNTER = 0
26+
DEMO_UUID_COUNTER : int = 0
2727

28-
def configure():
28+
def configure() -> None:
2929
global USE_DEMO_UUID
3030

3131
if os.getenv("DEMO_UUID_REQUESTING_NONRANDOM") == "NONRANDOM_REQUESTED":
3232
USE_DEMO_UUID = True
3333

34-
def demo_uuid():
34+
def demo_uuid() -> str:
3535
"""
3636
This function generates a repeatable UUID, drawing on non-varying elements of the environment and process call for entropy.
3737
@@ -52,16 +52,17 @@ def demo_uuid():
5252
parts.append(str(DEMO_UUID_COUNTER))
5353

5454
# Component: Present working directory, replacing $HOME with '~'.
55-
parts.append(os.getcwd().replace(os.getenv("HOME"), "~"))
55+
env_HOME : str = os.getenv("HOME", "/nonexistent")
56+
parts.append(os.getcwd().replace(env_HOME, "~"))
5657

5758
# Component: Argument vector.
5859
parts.extend(sys.argv)
5960

6061
return str(uuid.uuid5(uuid.NAMESPACE_URL, "/".join(parts)))
6162

62-
def local_uuid():
63+
def local_uuid() -> str:
6364
"""
64-
Generate either a UUID4, or if requested via environment configuration, a non-random demo UUID. Returns a string.
65+
Generate either a UUID4, or if requested via environment configuration, a non-random demo UUID.
6566
"""
6667
global USE_DEMO_UUID
6768
if USE_DEMO_UUID:

0 commit comments

Comments
 (0)