Skip to content

call function treats empty-tuples and None and no-argument type differently #405

Description

@anilbeycorintis

Hi I first reported this on Firedrake [https://github.com/firedrakeproject/firedrake/issues/4452] and the maintainers suggested here is the place.

Description

The behaviour of subdomain_id varies between the empty tuple case, None case, and no-argument cases.

fd.dx()         ✅  # Equivalent to Measure('cell', subdomain_id='everywhere')
fd.dx(None)     ✅  # Same as above
fd.dx(())       ❓  # Accepted, but becomes Measure('cell', subdomain_id=()), not 'everywhere'

As a result, these two functions behave differently. Shouldn't passing None and empty container behave the same?

1. Implementation with empty tuples

def get_subdomains() -> tuple[int]:
    """Returns the fluid subdomains."""
    result = fetch_result()
    return result

fd.dx(get_subdomains())

2. Implementation with the optional types

def get_subdomains() -> tuple[int] | None:
    """Returns the fluid subdomains."""
    result = fetch_result()
    if len(result) == 0:
        return None
    else:
        return result

subdomains: tuple[int] | None = get_subdomains()
fd.dx(subdomains)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions