-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Region.EMPTY
instead of None
#624
base: main
Are you sure you want to change the base?
Conversation
`None` means an empty region, for example the result of `Region.intersect` if the input regions don't overlap. We can handle `None` on either side of the operator, by implementing the reflected operators (`__radd__` and `__rsub__`). See https://docs.python.org/3/reference/datamodel.html#object.__radd__ We still can't support `None + None` but that's a limitation I can live with for now. Fixing this properly will require adding a new singleton to represent empty regions, changing `Region.intersect` to return that instead of `None`, and updating the implementation of all our other region-handling code. There's a (out of date) pull request for that: #624
Yes,
0, I think.
EMPTY, definitely better. |
Interesting. That's still true as of Python 3.10.5. |
None
as Region
with Region.NONE
Region.EMPTY
instead of None
633f783
to
391a83f
Compare
I think this is a bit neater.
This may make it easier to use functions that return a `Region` that might be `None` because in many cases they may not need to check `region is None` before performing operations on that region. It also makes it easier to implement functions with take a default `Region` because we can follow the standard `region is not None` to mean "did the caller pass a region argument". For an example of this see `Grid`.
Rebased on master to resolve conflicts. |
This may make it easier to use functions that return a
Region
that mightbe
None
because in many cases they may not need to checkregion is None
before performing operations on that region. It also makes it easier to
implement functions with take a default
Region
because we can follow thestandard
region is not None
to mean "did the caller pass a regionargument". For an example of this see
Grid
.I don't think this should go in the next release. It would be better to let it bake for a while.
TODO:
Region.NONE == Region.NONE
? CurrentlyRegion.NONE == Region.NONE
, butRegion.NONE != Region(float('nan'), float('nan'), float('nan'), float('nan'))
becauseNAN != NAN
andNAN != float('nan')
but(NAN,) == (NAN,)
and(NAN,) != (float('nan'))
Region.NONE.width == 0
ornan
?, equally for heightNONE
a good name? PerhapsEMPTY
would be better?None
asRegion
in our codebase.