0

Hello I am using Python 3.8

And I am implementing a dataclass with a fix list in order to do this I have the following code:

from dataclasses import dataclass
from typing import Annotated, List, ValueRange
from pydantic import validate_arguments

@validate_arguments
@dataclass
class WorldArea:
    ...
    data: Annotated[List[float], ValueRange(1, 3)]
    ...

The idea is that data will be a list with 1, 2 or 3 elements, as you can see I am using Annotated and ValueRange, but when I execute I get the following error:

File "a.py", line 2, in from typing import List, ValueRange ImportError: cannot import name 'Annotated' from 'typing'

File "a.py", line 2, in from typing import List, ValueRange ImportError: cannot import name 'ValueRange' from 'typing'

Tlaloc-ES
  • 4,825
  • 7
  • 38
  • 84

1 Answers1

8

Annotated has been introduced in Python 3.9 (see last line in the linked section).

ValueRange (and MaxLen) in the linked section appear to be example classes.

They are not part of the typing package.

Paul P
  • 3,346
  • 2
  • 12
  • 26