intervaltree
intervaltree copied to clipboard
Support type annotations via typing.Generic
It would be great if both the range value type and mapped value type could be annotated with type annotations, e.g.:
@dataclass
class Foo:
a: int
b: str
tree = IntervalTree[int, Foo]()
tree[2, 5] = Foo(123, 'test')
# linter should raise type error:
tree[1.4, 2.3] = Foo(123, 'test')
# linter should raise type error:
tree[2, 5] = 'invalid value type'
Here are some experimental type stubs: https://github.com/Lubba-64/intervaltree-stubs
@Lubba-64 how do we use them?
I created these type stubs while in a clone of the original repo. I do not recall how or if I set it up for production, I ended up with a custom solution to replace this library anyways since my use case was different.