mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 15:36:59 +08:00
Opt: Add type hint for cached_property
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import random
|
||||
import re
|
||||
from functools import wraps
|
||||
from typing import Callable, Generic, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -74,19 +77,20 @@ class Config:
|
||||
return decorate
|
||||
|
||||
|
||||
class cached_property:
|
||||
class cached_property(Generic[T]):
|
||||
"""
|
||||
cached-property from https://github.com/pydanny/cached-property
|
||||
Add typing support
|
||||
|
||||
A property that is only computed once per instance and then replaces itself
|
||||
with an ordinary attribute. Deleting the attribute resets the property.
|
||||
Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
|
||||
"""
|
||||
|
||||
def __init__(self, func):
|
||||
def __init__(self, func: Callable[..., T]):
|
||||
self.func = func
|
||||
|
||||
def __get__(self, obj, cls):
|
||||
def __get__(self, obj, cls) -> T:
|
||||
if obj is None:
|
||||
return self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user