fcurella / django-fakery

🏭 An easy-to-use implementation of Creation Methods for Django, backed by Faker.
http://django-fakery.readthedocs.org/en/stable/
MIT License
115 stars 6 forks source link

Check for Empty values with is operator #72

Closed mjakob closed 1 year ago

mjakob commented 1 year ago

Greetings! I did not create an issue for this before hand but let me know if you want one.

What does this changes

By using the is operator to check for empty values the package can support custom fields that have values that override the comparison operators (__eq__ and __ne__), like numpy arrays.

What was wrong

>>> import numpy as np
>>> from django_fakery.faker_factory import Empty
>>> if np.arange(3) != Empty:
...     print("success")
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

How this fixes it

>>> if np.arange(3) is not Empty:
...     print("success")
... 
success