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

Method __new__

Lib/_pydatetime.py:1425–1462  ·  view source on GitHub ↗

Constructor. Arguments: hour, minute (required) second, microsecond (default to zero) tzinfo (default to None) fold (keyword only, default to zero)

(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)

Source from the content-addressed store, hash-verified

1423 __slots__ = '_hour', '_minute', '_second', '_microsecond', '_tzinfo', '_hashcode', '_fold'
1424
1425 def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0):
1426 """Constructor.
1427
1428 Arguments:
1429
1430 hour, minute (required)
1431 second, microsecond (default to zero)
1432 tzinfo (default to None)
1433 fold (keyword only, default to zero)
1434 """
1435 if (isinstance(hour, (bytes, str)) and len(hour) == 6 and
1436 ord(hour[0:1])&0x7F < 24):
1437 # Pickle support
1438 if isinstance(hour, str):
1439 try:
1440 hour = hour.encode('latin1')
1441 except UnicodeEncodeError:
1442 # More informative error message.
1443 raise ValueError(
1444 "Failed to encode latin1 string when unpickling "
1445 "a time object. "
1446 "pickle.load(data, encoding='latin1') is assumed.")
1447 self = object.__new__(cls)
1448 self.__setstate(hour, minute or None)
1449 self._hashcode = -1
1450 return self
1451 hour, minute, second, microsecond, fold = _check_time_fields(
1452 hour, minute, second, microsecond, fold)
1453 _check_tzinfo_arg(tzinfo)
1454 self = object.__new__(cls)
1455 self._hour = hour
1456 self._minute = minute
1457 self._second = second
1458 self._microsecond = microsecond
1459 self._tzinfo = tzinfo
1460 self._hashcode = -1
1461 self._fold = fold
1462 return self
1463
1464 @classmethod
1465

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected