-
I encountered this surprising behavior: def example1(nums: tuple[int, ...]):
if len(nums) == 0 or len(nums) > 1:
return
reveal_type(nums) # Type of "nums" is "tuple[()] | tuple[int]"
def example2(nums: tuple[int, ...]):
if len(nums) <= 0 or len(nums) > 1:
return
reveal_type(nums) # Type of "nums" is "tuple[int]" Tuples can't have negative length, so I would expect def example3(nums: tuple[int, ...]):
if len(nums) < 0:
return # Type analysis indicates code is unreachable
elif len(nums) == 0 or len(nums) > 1:
return
reveal_type(nums) # Type of "nums" is "tuple[()] | tuple[int]" Is this intended? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
As an aside, I would also expect def example4(nums: tuple[int, ...]):
if len(nums) < 0 or len(nums) == 0 or len(nums) > 1:
return
reveal_type(nums) # Type of "nums" is "tuple[()] | tuple[int]" But that might be a separate issue. |
Beta Was this translation helpful? Give feedback.
No, this looks like a bug. Thanks for reporting it. I'll create a bug report from this discussion.