MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / __new__

Method __new__

tools/python-3.11.9-amd64/Lib/datetime.py:923–953  ·  view source on GitHub ↗

Constructor. Arguments: year, month, day (required, base 1)

(cls, year, month=None, day=None)

Source from the content-addressed store, hash-verified

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

Callers 5

__new__Method · 0.45
__new__Method · 0.45
__new__Method · 0.45
__new__Method · 0.45
_createMethod · 0.45

Calls 3

__setstateMethod · 0.95
_check_date_fieldsFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected