Skip to content

How to deal with overlapping protocols. #1491

Answered by Daverball
randolf-scholz asked this question in Q&A
Discussion options

You must be logged in to vote

I would probably use overloads on __init__ for this:

    @overload
    def __init__(self: Sampler[int], data_source: IterableDataset[int, Any]) -> None: ...
    
    @overload
    def __init__(self: Sampler[K], data_source: MapDataset[K, Any]) -> None: ...

    def __init__(self, data_source: Dataset[Any, Any]) -> None:

using Any in the function annotation instead of K avoids type errors in the implementation of __init__, but you could also just use type:ignore comments.

You could also probably simplify things by getting rid of Int_contra in IterableDataset I don't think you get anything valuable out of it.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Daverball
Comment options

@randolf-scholz
Comment options

@randolf-scholz
Comment options

Answer selected by randolf-scholz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants