From 6a0066bbda06ea0a43196e08f32dc171f33646b7 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 25 Aug 2021 08:22:53 -0700 Subject: [PATCH] Use Python 3 metaclass syntax Allows removing Python 2 compatibility shim from six. Obviates the need to override the `__new__` method. --- freezegun/api.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/freezegun/api.py b/freezegun/api.py index f308fb6f..239ae934 100644 --- a/freezegun/api.py +++ b/freezegun/api.py @@ -132,11 +132,6 @@ def _get_cached_module_attributes(module): return cached_attrs -# Stolen from six -def with_metaclass(meta, *bases): - """Create a base class with a metaclass.""" - return meta("NewBase", bases, {}) - _is_cpython = ( hasattr(platform, 'python_implementation') and platform.python_implementation().lower() == "cpython" @@ -309,10 +304,7 @@ def date_to_fakedate(date): date.day) -class FakeDate(with_metaclass(FakeDateMeta, real_date)): - def __new__(cls, *args, **kwargs): - return real_date.__new__(cls, *args, **kwargs) - +class FakeDate(real_date, metaclass=FakeDateMeta): def __add__(self, other): result = real_date.__add__(self, other) if result is NotImplemented: @@ -355,10 +347,7 @@ def __subclasscheck__(cls, subclass): return issubclass(subclass, real_datetime) -class FakeDatetime(with_metaclass(FakeDatetimeMeta, real_datetime, FakeDate)): - def __new__(cls, *args, **kwargs): - return real_datetime.__new__(cls, *args, **kwargs) - +class FakeDatetime(real_datetime, FakeDate, metaclass=FakeDatetimeMeta): def __add__(self, other): result = real_datetime.__add__(self, other) if result is NotImplemented: