11import re
2- from typing import TYPE_CHECKING , Generic , Iterable , List , Optional , TypeVar , Union
2+ from typing import TYPE_CHECKING , Any , Callable , Generic , Iterable , List , Optional , TypeVar , Union , overload
33import weakref
44from functools import cached_property
55from urllib .parse import parse_qsl , urlencode , urlparse
1212if TYPE_CHECKING :
1313 from plexapi .server import PlexServer
1414
15- PlexObjectT = TypeVar ("PlexObjectT" , bound = 'PlexObject' )
16- MediaContainerT = TypeVar ("MediaContainerT" , bound = "MediaContainer" )
15+ _T = TypeVar ('_T' )
1716
18- USER_DONT_RELOAD_FOR_KEYS = set ()
19- _DONT_RELOAD_FOR_KEYS = {'key' , 'sourceURI' }
17+ PlexObjectT = TypeVar ('PlexObjectT' , bound = 'PlexObject' )
18+ MediaContainerT = TypeVar ('MediaContainerT' , bound = 'MediaContainer' )
19+
20+ USER_DONT_RELOAD_FOR_KEYS : set [str ] = set ()
21+ _DONT_RELOAD_FOR_KEYS : set [str ] = {'key' , 'sourceURI' }
2022OPERATORS = {
2123 'exact' : lambda v , q : v == q ,
2224 'iexact' : lambda v , q : v .lower () == q .lower (),
3840}
3941
4042
41- class cached_data_property (cached_property ):
43+ class cached_data_property (cached_property , Generic [ _T ] ):
4244 """Caching for PlexObject data properties.
4345
4446 This decorator creates properties that cache their values with
4547 automatic invalidation on data changes.
4648 """
4749
48- def __new__ ( cls , * args , ** kwargs ) -> "cached_data_property" :
49- return super ().__new__ ( cls )
50+ def __init__ ( self , func : Callable [[ Any ], _T ] ) -> None :
51+ super ().__init__ ( func )
5052
5153 def __set_name__ (self , owner , name ):
5254 """Register the annotated property in the parent class's _cached_data_properties set."""
@@ -55,6 +57,17 @@ def __set_name__(self, owner, name):
5557 owner ._cached_data_properties = set ()
5658 owner ._cached_data_properties .add (name )
5759
60+ @overload
61+ def __get__ (self , instance : None , owner : type | None = None ) -> "cached_data_property[_T]" :
62+ ...
63+
64+ @overload
65+ def __get__ (self , instance : object , owner : type | None = None ) -> _T :
66+ ...
67+
68+ def __get__ (self , instance : object | None , owner : type | None = None ) -> "cached_data_property[_T] | _T" :
69+ return super ().__get__ (instance , owner )
70+
5871
5972class PlexObjectMeta (type ):
6073 """Metaclass for PlexObject to handle cached_data_properties."""
@@ -76,6 +89,11 @@ def __new__(mcs, name, bases, attrs):
7689 return super ().__new__ (mcs , name , bases , attrs )
7790
7891
92+ class MediaContainerMeta (PlexObjectMeta , type (List )):
93+ """Metaclass for MediaContainer that combines PlexObjectMeta with Generic/List metaclass."""
94+ pass
95+
96+
7997class PlexObject (metaclass = PlexObjectMeta ):
8098 """ Base class for all Plex objects.
8199
@@ -1144,6 +1162,7 @@ class MediaContainer(
11441162 Generic [PlexObjectT ],
11451163 List [PlexObjectT ],
11461164 PlexObject ,
1165+ metaclass = PlexObjectMeta ,
11471166):
11481167 """ Represents a single MediaContainer.
11491168
0 commit comments