call function treats empty-tuples and None and no-argument type differently
- Dominant language
- Python
- Stars
- 150
- Forks
- 79
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 10
Description
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.
```python
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
```python
def get_subdomains() -> tuple[int]:
"""Returns the fluid subdomains."""
result = fetch_result()
return result
fd.dx(get_subdomains())
```
#### 2. Implementation with the optional types
```python
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)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.