MCPcopy Index your code
hub / github.com/python/cpython / __new__

Method __new__

Lib/_pydatetime.py:990–1020  ·  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

988 __slots__ = '_year', '_month', '_day', '_hashcode'
989
990 def __new__(cls, year, month=None, day=None):
991 """Constructor.
992
993 Arguments:
994
995 year, month, day (required, base 1)
996 """
997 if (month is None and
998 isinstance(year, (bytes, str)) and len(year) == 4 and
999 1 <= ord(year[2:3]) <= 12):
1000 # Pickle support
1001 if isinstance(year, str):
1002 try:
1003 year = year.encode('latin1')
1004 except UnicodeEncodeError:
1005 # More informative error message.
1006 raise ValueError(
1007 "Failed to encode latin1 string when unpickling "
1008 "a date object. "
1009 "pickle.load(data, encoding='latin1') is assumed.")
1010 self = object.__new__(cls)
1011 self.__setstate(year)
1012 self._hashcode = -1
1013 return self
1014 year, month, day = _check_date_fields(year, month, day)
1015 self = object.__new__(cls)
1016 self._year = year
1017 self._month = month
1018 self._day = day
1019 self._hashcode = -1
1020 return self
1021
1022 # Additional constructors
1023

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