mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-23 09:19:58 +00:00
fix Type::cycle_normalized
This commit is contained in:
parent
c5bd2cde55
commit
1d1afaa517
3 changed files with 24 additions and 2 deletions
|
|
@ -70,3 +70,24 @@ def descent(x: int, y: int):
|
|||
|
||||
def count_set_bits(n):
|
||||
return 1 + count_set_bits(n & n - 1) if n else 0
|
||||
|
||||
class Literal:
|
||||
def __invert__(self):
|
||||
return Literal()
|
||||
|
||||
class OR:
|
||||
def __invert__(self):
|
||||
return AND()
|
||||
|
||||
class AND:
|
||||
def __invert__(self):
|
||||
return OR()
|
||||
|
||||
def to_NNF(cond):
|
||||
if cond:
|
||||
return ~to_NNF(cond)
|
||||
if cond:
|
||||
return OR()
|
||||
if cond:
|
||||
return AND()
|
||||
return Literal()
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ def list_int(x: int):
|
|||
return list1(x)
|
||||
|
||||
# TODO: should be `list[int]`
|
||||
reveal_type(list_int(1)) # revealed: list[Divergent] | list[int] | list[Divergent]
|
||||
reveal_type(list_int(1)) # revealed: list[Divergent] | list[Divergent] | list[int]
|
||||
|
||||
def tuple_obj(cond: bool):
|
||||
if cond:
|
||||
|
|
|
|||
|
|
@ -966,7 +966,8 @@ impl<'db> Type<'db> {
|
|||
if has_divergent_type_in_cycle(previous) && !has_divergent_type_in_cycle(self) {
|
||||
self
|
||||
} else {
|
||||
UnionType::from_elements_cycle_recovery(db, [self, previous])
|
||||
// The current type is unioned to the previous type. Unioning in the reverse order can cause the fixed-point iterations to converge slowly or even fail.
|
||||
UnionType::from_elements_cycle_recovery(db, [previous, self])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue