Skip to content

Commit f23bc2c

Browse files
committed
Make test_is_nullish less numpy specific
1 parent d16ce14 commit f23bc2c

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current version 3.0.0a2 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.4.2.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 1965 unit tests.
19+
of currently 1966 unit tests.
2020

2121

2222
## Documentation

src/graphql/pyutils/is_finite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import Any
21
from math import isfinite
2+
from typing import Any
33

44
__all__ = ["is_finite"]
55

src/graphql/pyutils/is_integer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import Any
21
from math import isfinite
2+
from typing import Any
33

44
__all__ = ["is_integer"]
55

src/graphql/pyutils/is_nullish.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import math
1+
from math import isnan
22
from typing import Any
33

44
from ..error import INVALID
@@ -9,7 +9,5 @@
99
def is_nullish(value: Any) -> bool:
1010
"""Return true if a value is null, undefined, or NaN."""
1111
return (
12-
value is None
13-
or value is INVALID
14-
or (isinstance(value, float) and math.isnan(value))
12+
value is None or value is INVALID or (isinstance(value, float) and isnan(value))
1513
)

tests/pyutils/test_is_nullish.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,22 @@ def undefined_is_nullish():
4444
assert is_nullish(INVALID) is True
4545

4646
def nan_is_nullish():
47-
assert is_nullish(nan)
47+
assert is_nullish(nan) is True
4848

49-
def numpy_arrays_are_not_nullish():
50-
assert is_nullish(FakeNumpyArray()) is False
49+
def irreflexive_objects_are_not_nullish():
50+
# Numpy arrays operate element-wise and the comparison operator returns arrays.
51+
# Similar to math.nan, they are therefore not equal to themselves. However, we
52+
# only want math.nan to be considered nullish, not values like numpy arrays.
53+
54+
class IrreflexiveValue:
55+
def __eq__(self, other):
56+
return False
57+
58+
def __bool__(self):
59+
return False
60+
61+
value = IrreflexiveValue()
62+
assert value != value
63+
assert not value
64+
65+
assert is_nullish(value) is False

0 commit comments

Comments
 (0)