Constructor. Arguments: year, month, day (required, base 1)
(cls, year, month=None, day=None)
| 921 | __slots__ = '_year', '_month', '_day', '_hashcode' |
| 922 | |
| 923 | def __new__(cls, year, month=None, day=None): |
| 924 | """Constructor. |
| 925 | |
| 926 | Arguments: |
| 927 | |
| 928 | year, month, day (required, base 1) |
| 929 | """ |
| 930 | if (month is None and |
| 931 | isinstance(year, (bytes, str)) and len(year) == 4 and |
| 932 | 1 <= ord(year[2:3]) <= 12): |
| 933 | # Pickle support |
| 934 | if isinstance(year, str): |
| 935 | try: |
| 936 | year = year.encode('latin1') |
| 937 | except UnicodeEncodeError: |
| 938 | # More informative error message. |
| 939 | raise ValueError( |
| 940 | "Failed to encode latin1 string when unpickling " |
| 941 | "a date object. " |
| 942 | "pickle.load(data, encoding='latin1') is assumed.") |
| 943 | self = object.__new__(cls) |
| 944 | self.__setstate(year) |
| 945 | self._hashcode = -1 |
| 946 | return self |
| 947 | year, month, day = _check_date_fields(year, month, day) |
| 948 | self = object.__new__(cls) |
| 949 | self._year = year |
| 950 | self._month = month |
| 951 | self._day = day |
| 952 | self._hashcode = -1 |
| 953 | return self |
| 954 | |
| 955 | # Additional constructors |
| 956 |