aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools/fcid.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2021-11-03 12:29:39 -0700
committerBryan Newbold <bnewbold@robocracy.org>2021-11-03 12:31:07 -0700
commit10a2374051568edf3d872988e730328d899a0fdd (patch)
tree795be5e149a021f84bc4305c1811e63cc86f7aa1 /python/fatcat_tools/fcid.py
parentcfab1ddcd8a05b62ecc16763d18a6ecee8fa234f (diff)
downloadfatcat-10a2374051568edf3d872988e730328d899a0fdd.tar.gz
fatcat-10a2374051568edf3d872988e730328d899a0fdd.zip
typing: first batch of python bulk type annotations
While these changes are more delicate than simple lint changes, this specific batch of edits and annotations was *relatively* simple, and resulted in few code changes other than function signature additions.
Diffstat (limited to 'python/fatcat_tools/fcid.py')
-rw-r--r--python/fatcat_tools/fcid.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/python/fatcat_tools/fcid.py b/python/fatcat_tools/fcid.py
index 53891e5a..07463f62 100644
--- a/python/fatcat_tools/fcid.py
+++ b/python/fatcat_tools/fcid.py
@@ -2,17 +2,17 @@ import base64
import uuid
-def fcid2uuid(s):
+def fcid2uuid(fcid: str) -> str:
"""
Converts a fatcat identifier (base32 encoded string) to a uuid.UUID object
"""
- s = s.split("_")[-1].upper().encode("utf-8")
- assert len(s) == 26
- raw = base64.b32decode(s + b"======")
- return str(uuid.UUID(bytes=raw)).lower()
+ b = fcid.split("_")[-1].upper().encode("utf-8")
+ assert len(b) == 26
+ raw_bytes = base64.b32decode(b + b"======")
+ return str(uuid.UUID(bytes=raw_bytes)).lower()
-def uuid2fcid(s):
+def uuid2fcid(s: str) -> str:
"""
Converts a uuid.UUID object to a fatcat identifier (base32 encoded string)
"""
@@ -20,6 +20,6 @@ def uuid2fcid(s):
return base64.b32encode(raw)[:26].lower().decode("utf-8")
-def test_fcid():
+def test_fcid() -> None:
test_uuid = "00000000-0000-0000-3333-000000000001"
assert test_uuid == fcid2uuid(uuid2fcid(test_uuid))