Strongly typed helper functions for object store __getitem__ and Tree.lookup_path #1457
castedo
started this conversation in
Show and tell
Replies: 1 comment 3 replies
-
|
A simpler way to achieve what you want is to use typing.cast: from typing import cast
from dulwich.objects import Tree
tree = cast(Tree, repo[tree_id])
mode, sha = tree.lookup_path(lookup, str(path).encode("ascii"))
... |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Folks that use mypy (or similar) for type checking (especially in strict mode) might find either of these two helper functions useful. Or perhaps just some of the type-checking techniques demonstrated. This code will run on Python 3.9 (but you need much higher to run with mypy). I found them useful when porting from GitPython to Dulwich.
I've organized them into this small file:
https://gitlab.com/perm.pub/hidos/-/blob/912e65b32e872db48267d08105a2f4b119479853/hidos/dulwish.py
The contents are also copied below:
Beta Was this translation helpful? Give feedback.
All reactions