Skip to content

Conversation

@campospinto
Copy link
Collaborator

When a Union is created with no arguments, return an empty list instead of a None object. This should allow to iterate over empty "Union" objects.

Fixes #183

Comment on lines -139 to 146
# a. If the required Union contains no domains, return None;
# a. If the required Union contains no domains, return an empty tuple;
# b. If it contains a single domain, return the domain itself;
# c. If it contains multiple domains, create a Union object.
if not args:
obj = None
obj = ()
elif len(args) == 1:
obj = args[0]
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand why we need this change for the case of an empty Union, but not for a Union containing a single domain. If being able to iterate is really important, why not doing it for all cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, single domain unions should be handled consistently.
I just wanted to see whether the modification for empty unions was passing the tests before looking at the case of a single element.

I have no idea whether "unions" should be iterable objects, I just saw that we iterate on them in some places and currently this raises an error when the union is empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps -- according to the mathematical usage, a "union" of domains (sets in Rd) is a priori a domain itself, so it's unclear what we should get when iterating over it: subdomains ? points ?

Maybe the issue comes from the fact that some objects expected to be iterable (like interiors, boundaries or interfaces ) are currently defined as "unions"...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I'm turning this into a draft -- we should probably discuss in issue #183 how to better solve this problem

@campospinto campospinto marked this pull request as draft December 12, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iterating over an empty Union raises an error

3 participants