intervaltree icon indicating copy to clipboard operation
intervaltree copied to clipboard

Support type annotations via typing.Generic

Open honorabel opened this issue 3 years ago • 3 comments

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'

honorabel avatar Jan 30 '23 18:01 honorabel

Here are some experimental type stubs: https://github.com/Lubba-64/intervaltree-stubs

Lubba-64 avatar Feb 17 '23 19:02 Lubba-64

@Lubba-64 how do we use them?

iainelder avatar Jan 04 '24 04:01 iainelder

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.

Lubba-64 avatar Jan 05 '24 00:01 Lubba-64