Skip to content
Discussion options

You must be logged in to vote

Narrowing val from Val to Slice[Val] would not be sound in this case. For example, if do_something receives an object of type Slice[Add], it would be unsound for the value's type to be Slice[Val] within the block guarded by isinstance(val, Slice). Such a type would allow you to overwrite the value field with an object that is not compatible with Add.

I have considered changing the narrowing behavior of isinstance in the case where type parameters are covariant. In that circumstances, I think it would be OK to use the upper bound rather than Unknown. Likewise, it should be possible to use the lower bound (Never) in the case of contravariant type parameters. But I don't see a way around Unk…

Replies: 1 comment 3 replies

Comment options

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

@erictraut
Comment options

@TMVector
Comment options

Answer selected by TMVector
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