omegaconf icon indicating copy to clipboard operation
omegaconf copied to clipboard

`List[Tuple[T, ...]]` not supported

Open ganler opened this issue 2 years ago • 1 comments

Describe the bug Maybe I am wrong, but it seems List[List[T]] is supported while List[Tuple[T, ...]] is not.

To Reproduce

from dataclasses import dataclass
from typing import List, Dict, Tuple, Type

from omegaconf import OmegaConf


@dataclass
class A:
    in_dtypes: List[Tuple[int, ...]]
    out_dtypes: List[Tuple[int, ...]]


OmegaConf.structured(A)

Expected behavior List[Tuple[T, ...]] can be very useful in terms of supporting "a list of available arguments" that I hope omegaconf can support.

Additional context

  • [x] OmegaConf version: 2.2.3
  • [x] Python version: 3.8
  • [x] Operating system: ubuntu2004
  • [x] Please provide a minimal repro

ganler avatar Aug 29 '22 16:08 ganler

Currently support for Tuple types is spotty. OmegaConf has first-class support for list and dict, but not for tuple.

Internally, OmegaConf treats Tuple[int, ...] as being equivalent to List[int], i.e. the runtime type checking behavior is the same in both of those cases. For tuple type annotations with multiple type arguments, OmegaConf (currently) only honors the first type arg, e.g. Tuple[int, str, float] is treated by OmegaConf as List[int].

Anyway, thanks for the report. We are slowly expanding what OmegaConf can do with regard to Tuple.

Jasha10 avatar Aug 29 '22 19:08 Jasha10