Skip to content
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

Allow homogeneous tuples as read-only function arguments #738

Open
Tracked by #1566
yguclu opened this issue Feb 11, 2021 · 1 comment · May be fixed by #1850
Open
Tracked by #1566

Allow homogeneous tuples as read-only function arguments #738

yguclu opened this issue Feb 11, 2021 · 1 comment · May be fixed by #1850
Assignees
Labels
Containers tuples/lists/sets/maps Feature adding new features Type specification
Milestone

Comments

@yguclu
Copy link
Member

yguclu commented Feb 11, 2021

As a USER, I would like to pass homogeneous tuples to a function, in order to reduce the number of arguments.

Use case

In a numerical simulation, homogeneous tuples are often used to collect parameters together in a logical fashion. For example:

  • degrees = (2, 3, 3) may be the polynomial degree along each dimension (x1, x2, x3) of the computational domain;
  • ncells = (100, 200, 200) may be the number of grid cells along (x1, x2, x3);
  • periodic = (False, False, True) may tell whether the domain is periodic along (x1, x2, x3).

It is convenient to pass these parameters as tuples, rather than unpacking their contents:

def func(degrees: tuple[int], ncells: tuple[int], periodic: tuple[bool], ... ):

References

For the annotation style in this case, see https://www.python.org/dev/peps/pep-0585/

@yguclu yguclu changed the title Allow homogeneous tuples as read-only arguments Allow homogeneous tuples as read-only function arguments Feb 11, 2021
@yguclu yguclu added this to the Sprint 21/2/1 milestone Feb 11, 2021
@yguclu yguclu added the Feature adding new features label Feb 12, 2021
@MenoIy MenoIy self-assigned this Feb 16, 2021
@EmilyBourne
Copy link
Member

This syntax doesn't seem quite right. As I understand it tuple[int] would be a tuple of length 1 containing an integer. The syntax for homogeneous tuples seems to be tuple[int, ...] (see https://mypy.readthedocs.io/en/stable/kinds_of_types.html#tuple-types)

@EmilyBourne EmilyBourne mentioned this issue Oct 18, 2023
10 tasks
@EmilyBourne EmilyBourne added the Containers tuples/lists/sets/maps label Dec 25, 2023
@EmilyBourne EmilyBourne linked a pull request Apr 23, 2024 that will close this issue
@EmilyBourne EmilyBourne self-assigned this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Containers tuples/lists/sets/maps Feature adding new features Type specification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants