mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Tentative fix for resolve_fraction_unit ZeroDivision error
I'll admit to not really following what the code does, so will really need someone with a better understanding of the aim of this code to look over the proposed fix; but based on a bunch of runs and hand-debugging, this seems to do the job. This passes all existing tests and also removes the reported error. On the other hand I'm not confident that I'm *not* just masking an underlying issue with this function.
This commit is contained in:
@@ -143,7 +143,7 @@ def resolve_fraction_unit(
|
|||||||
resolved: list[Fraction | None] = [None] * len(resolve)
|
resolved: list[Fraction | None] = [None] * len(resolve)
|
||||||
remaining_fraction = Fraction(sum(scalar.value for scalar, _, _ in resolve))
|
remaining_fraction = Fraction(sum(scalar.value for scalar, _, _ in resolve))
|
||||||
|
|
||||||
while True:
|
while remaining_fraction:
|
||||||
remaining_space_changed = False
|
remaining_space_changed = False
|
||||||
resolve_fraction = Fraction(remaining_space, remaining_fraction)
|
resolve_fraction = Fraction(remaining_space, remaining_fraction)
|
||||||
for index, (scalar, min_value, max_value) in enumerate(resolve):
|
for index, (scalar, min_value, max_value) in enumerate(resolve):
|
||||||
@@ -166,7 +166,7 @@ def resolve_fraction_unit(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
Fraction(remaining_space, remaining_fraction)
|
Fraction(remaining_space, remaining_fraction)
|
||||||
if remaining_space
|
if remaining_space > 0
|
||||||
else Fraction(1)
|
else Fraction(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -125,9 +125,6 @@ def test_resolve_fraction_unit():
|
|||||||
) == Fraction(2)
|
) == Fraction(2)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(
|
|
||||||
strict=True, reason="https://github.com/Textualize/textual/issues/2502"
|
|
||||||
)
|
|
||||||
def test_resolve_issue_2502():
|
def test_resolve_issue_2502():
|
||||||
"""Test https://github.com/Textualize/textual/issues/2502"""
|
"""Test https://github.com/Textualize/textual/issues/2502"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user