MCPcopy Index your code
hub / github.com/RustPython/RustPython / __new__

Method __new__

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

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

Callers 5

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

Calls 6

__setstateMethod · 0.95
isinstanceFunction · 0.85
lenFunction · 0.85
ordFunction · 0.85
_check_date_fieldsFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected