From 754407c587acb2b2a1afd9fa06480336bb3755b3 Mon Sep 17 00:00:00 2001 From: Lucas Colombo Date: Fri, 24 Nov 2023 01:22:08 -0300 Subject: [PATCH] fix: support _no_init on python 3.8 --- rodi/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/rodi/__init__.py b/rodi/__init__.py index 5852acf..d367dde 100644 --- a/rodi/__init__.py +++ b/rodi/__init__.py @@ -21,8 +21,9 @@ ) if sys.version_info >= (3, 9): # pragma: no cover - # Python 3.9 - from typing import _no_init_or_replace_init + from typing import _no_init_or_replace_init as _no_init +elif sys.version_info >= (3, 8): # pragma: no cover + from typing import _no_init try: from typing import Protocol @@ -584,12 +585,13 @@ def _ignore_class_attribute(self, key: str, value) -> bool: return is_classvar or is_initialized def _has_default_init(self): - if self.concrete_type.__init__ is object.__init__: + init = getattr(self.concrete_type, "__init__", None) + + if init is object.__init__: return True - if sys.version_info >= (3, 9): # pragma: no cover - # Python 3.9 - if self.concrete_type.__init__ is _no_init_or_replace_init: + if sys.version_info >= (3, 8): # pragma: no cover + if init is _no_init: return True return False