Construct a date from a string in ISO 8601 format.
(cls, date_string)
| 1047 | |
| 1048 | @classmethod |
| 1049 | def fromisoformat(cls, date_string): |
| 1050 | """Construct a date from a string in ISO 8601 format.""" |
| 1051 | |
| 1052 | if not isinstance(date_string, str): |
| 1053 | raise TypeError('Argument must be a str') |
| 1054 | |
| 1055 | if not date_string.isascii(): |
| 1056 | raise ValueError('Argument must be an ASCII str') |
| 1057 | |
| 1058 | if len(date_string) not in (7, 8, 10): |
| 1059 | raise ValueError(f'Invalid isoformat string: {date_string!r}') |
| 1060 | |
| 1061 | try: |
| 1062 | return cls(*_parse_isoformat_date(date_string)) |
| 1063 | except Exception: |
| 1064 | raise ValueError(f'Invalid isoformat string: {date_string!r}') |
| 1065 | |
| 1066 | @classmethod |
| 1067 | def fromisocalendar(cls, year, week, day): |