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

Method __new__

Lib/_pydatetime.py:1789–1822  ·  view source on GitHub ↗
(cls, year, month=None, day=None, hour=0, minute=0, second=0,
                microsecond=0, tzinfo=None, *, fold=0)

Source from the content-addressed store, hash-verified

1787 __slots__ = time.__slots__
1788
1789 def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
1790 microsecond=0, tzinfo=None, *, fold=0):
1791 if (isinstance(year, (bytes, str)) and len(year) == 10 and
1792 1 <= ord(year[2:3])&0x7F <= 12):
1793 # Pickle support
1794 if isinstance(year, str):
1795 try:
1796 year = bytes(year, 'latin1')
1797 except UnicodeEncodeError:
1798 # More informative error message.
1799 raise ValueError(
1800 "Failed to encode latin1 string when unpickling "
1801 "a datetime object. "
1802 "pickle.load(data, encoding='latin1') is assumed.")
1803 self = object.__new__(cls)
1804 self.__setstate(year, month)
1805 self._hashcode = -1
1806 return self
1807 year, month, day = _check_date_fields(year, month, day)
1808 hour, minute, second, microsecond, fold = _check_time_fields(
1809 hour, minute, second, microsecond, fold)
1810 _check_tzinfo_arg(tzinfo)
1811 self = object.__new__(cls)
1812 self._year = year
1813 self._month = month
1814 self._day = day
1815 self._hour = hour
1816 self._minute = minute
1817 self._second = second
1818 self._microsecond = microsecond
1819 self._tzinfo = tzinfo
1820 self._hashcode = -1
1821 self._fold = fold
1822 return self
1823
1824 # Read-only field accessors
1825 @property

Callers

nothing calls this directly

Calls 5

__setstateMethod · 0.95
_check_date_fieldsFunction · 0.85
_check_time_fieldsFunction · 0.85
_check_tzinfo_argFunction · 0.85
__new__Method · 0.45

Tested by

no test coverage detected