From 2c840e9e39c9aea596b7df0823d207ffd0f15ad1 Mon Sep 17 00:00:00 2001 From: Pierrick Rambaud Date: Sun, 4 Feb 2024 21:14:44 +0100 Subject: [PATCH] fix: use a custom staticmethod decorator --- geetools/ComputedObject/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/geetools/ComputedObject/__init__.py b/geetools/ComputedObject/__init__.py index d5b3394a..c304b978 100644 --- a/geetools/ComputedObject/__init__.py +++ b/geetools/ComputedObject/__init__.py @@ -11,6 +11,17 @@ from geetools.types import pathlike +# this hack is necessary for backward compatibility with Python < 3.10 +# for earlier version, staticmethod and classmethod were simply descriptors of the function +# making it impossible to call it from outside the class scope or to decorate it. +class _StaticMethod: + def __init__(self, func): + self.func = func + + def __get__(self, instance, owner=None): + return self.func + + # -- types management ---------------------------------------------------------- @_register_extention(ee.ComputedObject) def isInstance(self, klass: Type) -> ee.Number: @@ -68,7 +79,7 @@ def save(self, path: pathlike) -> Path: return path -@staticmethod # type: ignore +@_StaticMethod # type: ignore @_register_extention(ee.ComputedObject) # type: ignore def open(path: pathlike) -> ee.ComputedObject: """Open a .gee file as a ComputedObject.