mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-09-20 10:41:14 +00:00
Fix Python 3.13: classmethod + property unsupported (#448)
* Use own classproperty (don't inherit from property). * Config generation: Rename pathlib._local to pathlib
This commit is contained in:
committed by
GitHub
parent
d05b161e24
commit
1a2cb4d37d
@@ -1,3 +1,4 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Any, Optional
|
||||
|
||||
from akkudoktoreos.core.logging import get_logger
|
||||
@@ -5,13 +6,14 @@ from akkudoktoreos.core.logging import get_logger
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class classproperty(property):
|
||||
class classproperty:
|
||||
"""A decorator to define a read-only property at the class level.
|
||||
|
||||
This class extends the built-in `property` to allow a method to be accessed
|
||||
as a property on the class itself, rather than an instance. This is useful
|
||||
when you want a property-like syntax for methods that depend on the class
|
||||
rather than any instance of the class.
|
||||
This class replaces the built-in `property` which is no longer available in
|
||||
combination with @classmethod since Python 3.13 to allow a method to be
|
||||
accessed as a property on the class itself, rather than an instance. This
|
||||
is useful when you want a property-like syntax for methods that depend on
|
||||
the class rather than any instance of the class.
|
||||
|
||||
Example:
|
||||
class MyClass:
|
||||
@@ -28,13 +30,16 @@ class classproperty(property):
|
||||
decorated method on the class.
|
||||
|
||||
Parameters:
|
||||
fget (Callable[[type], Any]): A method that takes the class as an
|
||||
fget (Callable[[Any], Any]): A method that takes the class as an
|
||||
argument and returns a value.
|
||||
|
||||
Raises:
|
||||
AssertionError: If `fget` is not defined when `__get__` is called.
|
||||
"""
|
||||
|
||||
def __init__(self, fget: Callable[[Any], Any]) -> None:
|
||||
self.fget = fget
|
||||
|
||||
def __get__(self, _: Any, owner_cls: Optional[type[Any]] = None) -> Any:
|
||||
if owner_cls is None:
|
||||
return self
|
||||
|
Reference in New Issue
Block a user