mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
There was a discrepancy between the Python and C implementations. Add singletons ALWAYS_EQ, LARGEST and SMALLEST in test.support to test mixed type comparison.
This commit is contained in:
parent
5c72badd06
commit
17e52649c0
7 changed files with 107 additions and 84 deletions
|
@ -113,6 +113,7 @@ __all__ = [
|
|||
"run_with_locale", "swap_item",
|
||||
"swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
|
||||
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
|
||||
"ALWAYS_EQ", "LARGEST", "SMALLEST"
|
||||
]
|
||||
|
||||
class Error(Exception):
|
||||
|
@ -3103,6 +3104,41 @@ class FakePath:
|
|||
return self.path
|
||||
|
||||
|
||||
class _ALWAYS_EQ:
|
||||
"""
|
||||
Object that is equal to anything.
|
||||
"""
|
||||
def __eq__(self, other):
|
||||
return True
|
||||
def __ne__(self, other):
|
||||
return False
|
||||
|
||||
ALWAYS_EQ = _ALWAYS_EQ()
|
||||
|
||||
@functools.total_ordering
|
||||
class _LARGEST:
|
||||
"""
|
||||
Object that is greater than anything (except itself).
|
||||
"""
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, _LARGEST)
|
||||
def __lt__(self, other):
|
||||
return False
|
||||
|
||||
LARGEST = _LARGEST()
|
||||
|
||||
@functools.total_ordering
|
||||
class _SMALLEST:
|
||||
"""
|
||||
Object that is less than anything (except itself).
|
||||
"""
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, _SMALLEST)
|
||||
def __gt__(self, other):
|
||||
return False
|
||||
|
||||
SMALLEST = _SMALLEST()
|
||||
|
||||
def maybe_get_event_loop_policy():
|
||||
"""Return the global event loop policy if one is set, else return None."""
|
||||
return asyncio.events._event_loop_policy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue