Skip to content

Commit f90078c

Browse files
committed
Disabled instance caching for Entity's subclasses that do not explicitly enable it (to retain backward compatibility for existing classes that were not implemented with caching in mind).
Added caching keyword to Entity.from_inthandle. Fixed Player.from_userid not following the caching state of the current class unless explicitly specified. Added missing documentation.
1 parent 44f89f6 commit f90078c

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

addons/source-python/packages/source-python/entities/_base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ def __init__(cls, classname, bases, attributes):
8989

9090
# Set whether or not this class is caching its instances by default
9191
try:
92-
cls._caching = signature(
93-
cls.__init__
94-
).parameters['caching'].default
92+
cls._caching = bool(
93+
signature(
94+
vars(cls)['__init__']
95+
).parameters['caching'].default
96+
)
9597
except KeyError:
96-
cls._caching = True
98+
cls._caching = bool(vars(cls).get('caching', False))
9799

98100
# Add the class to the registered classes
99101
_entity_classes.add(cls)
@@ -300,14 +302,16 @@ def find_or_create(cls, classname):
300302
return entity
301303

302304
@classmethod
303-
def from_inthandle(cls, inthandle):
305+
def from_inthandle(cls, inthandle, caching=None):
304306
"""Create an entity instance from an inthandle.
305307
306308
:param int inthandle:
307309
The inthandle.
310+
:param bool caching:
311+
Whether to lookup the cache for an existing instance or not.
308312
:rtype: Entity
309313
"""
310-
return cls(index_from_inthandle(inthandle))
314+
return cls(index_from_inthandle(inthandle), caching=caching)
311315

312316
@classmethod
313317
def _obj(cls, ptr):

addons/source-python/packages/source-python/players/_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ def __init__(self, index, caching=True):
9292
object.__setattr__(self, '_playerinfo', None)
9393

9494
@classmethod
95-
def from_userid(cls, userid, caching=True):
95+
def from_userid(cls, userid, caching=None):
9696
"""Create an instance from a userid.
9797
9898
:param int userid:
9999
The userid.
100+
:param bool caching:
101+
Whether to lookup the cache for an existing instance or not.
100102
:rtype: Player
101103
"""
102104
return cls(index_from_userid(userid), caching=caching)

0 commit comments

Comments
 (0)