|
16 | 16 | def _cmp(x, y):
|
17 | 17 | return 0 if x == y else 1 if x > y else -1
|
18 | 18 |
|
| 19 | +def _get_class_module(self): |
| 20 | + module_name = self.__class__.__module__ |
| 21 | + if module_name == '_pydatetime': |
| 22 | + return 'datetime' |
| 23 | + else: |
| 24 | + return module_name |
| 25 | + |
19 | 26 | MINYEAR = 1
|
20 | 27 | MAXYEAR = 9999
|
21 | 28 | _MAXORDINAL = 3652059 # date.max.toordinal()
|
@@ -706,7 +713,7 @@ def __repr__(self):
|
706 | 713 | args.append("microseconds=%d" % self._microseconds)
|
707 | 714 | if not args:
|
708 | 715 | args.append('0')
|
709 |
| - return "%s.%s(%s)" % (self.__class__.__module__, |
| 716 | + return "%s.%s(%s)" % (_get_class_module(self), |
710 | 717 | self.__class__.__qualname__,
|
711 | 718 | ', '.join(args))
|
712 | 719 |
|
@@ -1016,7 +1023,7 @@ def __repr__(self):
|
1016 | 1023 | >>> repr(dt)
|
1017 | 1024 | 'datetime.datetime(2010, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)'
|
1018 | 1025 | """
|
1019 |
| - return "%s.%s(%d, %d, %d)" % (self.__class__.__module__, |
| 1026 | + return "%s.%s(%d, %d, %d)" % (_get_class_module(self), |
1020 | 1027 | self.__class__.__qualname__,
|
1021 | 1028 | self._year,
|
1022 | 1029 | self._month,
|
@@ -1510,7 +1517,7 @@ def __repr__(self):
|
1510 | 1517 | s = ", %d" % self._second
|
1511 | 1518 | else:
|
1512 | 1519 | s = ""
|
1513 |
| - s= "%s.%s(%d, %d%s)" % (self.__class__.__module__, |
| 1520 | + s= "%s.%s(%d, %d%s)" % (_get_class_module(self), |
1514 | 1521 | self.__class__.__qualname__,
|
1515 | 1522 | self._hour, self._minute, s)
|
1516 | 1523 | if self._tzinfo is not None:
|
@@ -2065,7 +2072,7 @@ def __repr__(self):
|
2065 | 2072 | del L[-1]
|
2066 | 2073 | if L[-1] == 0:
|
2067 | 2074 | del L[-1]
|
2068 |
| - s = "%s.%s(%s)" % (self.__class__.__module__, |
| 2075 | + s = "%s.%s(%s)" % (_get_class_module(self), |
2069 | 2076 | self.__class__.__qualname__,
|
2070 | 2077 | ", ".join(map(str, L)))
|
2071 | 2078 | if self._tzinfo is not None:
|
@@ -2372,10 +2379,10 @@ def __repr__(self):
|
2372 | 2379 | if self is self.utc:
|
2373 | 2380 | return 'datetime.timezone.utc'
|
2374 | 2381 | if self._name is None:
|
2375 |
| - return "%s.%s(%r)" % (self.__class__.__module__, |
| 2382 | + return "%s.%s(%r)" % (_get_class_module(self), |
2376 | 2383 | self.__class__.__qualname__,
|
2377 | 2384 | self._offset)
|
2378 |
| - return "%s.%s(%r, %r)" % (self.__class__.__module__, |
| 2385 | + return "%s.%s(%r, %r)" % (_get_class_module(self), |
2379 | 2386 | self.__class__.__qualname__,
|
2380 | 2387 | self._offset, self._name)
|
2381 | 2388 |
|
@@ -2638,26 +2645,3 @@ def _name_from_offset(delta):
|
2638 | 2645 | # small dst() may get within its bounds; and it doesn't even matter if some
|
2639 | 2646 | # perverse time zone returns a negative dst()). So a breaking case must be
|
2640 | 2647 | # pretty bizarre, and a tzinfo subclass can override fromutc() if it is.
|
2641 |
| - |
2642 |
| -try: |
2643 |
| - from _datetime import * |
2644 |
| -except ImportError: |
2645 |
| - pass |
2646 |
| -else: |
2647 |
| - # Clean up unused names |
2648 |
| - del (_DAYNAMES, _DAYS_BEFORE_MONTH, _DAYS_IN_MONTH, _DI100Y, _DI400Y, |
2649 |
| - _DI4Y, _EPOCH, _MAXORDINAL, _MONTHNAMES, _build_struct_time, |
2650 |
| - _check_date_fields, _check_time_fields, |
2651 |
| - _check_tzinfo_arg, _check_tzname, _check_utc_offset, _cmp, _cmperror, |
2652 |
| - _date_class, _days_before_month, _days_before_year, _days_in_month, |
2653 |
| - _format_time, _format_offset, _index, _is_leap, _isoweek1monday, _math, |
2654 |
| - _ord2ymd, _time, _time_class, _tzinfo_class, _wrap_strftime, _ymd2ord, |
2655 |
| - _divide_and_round, _parse_isoformat_date, _parse_isoformat_time, |
2656 |
| - _parse_hh_mm_ss_ff, _IsoCalendarDate, _isoweek_to_gregorian, |
2657 |
| - _find_isoformat_datetime_separator, _FRACTION_CORRECTION, |
2658 |
| - _is_ascii_digit) |
2659 |
| - # XXX Since import * above excludes names that start with _, |
2660 |
| - # docstring does not get overwritten. In the future, it may be |
2661 |
| - # appropriate to maintain a single module level docstring and |
2662 |
| - # remove the following line. |
2663 |
| - from _datetime import __doc__ |
0 commit comments