Skip to content

Commit 2ce7227

Browse files
committed
Removed a redundant layer to get Entity.index.
Removed some redundant extractions to get/set CachedProperty.__doc__. Fixed some docstrings.
1 parent 4cb773c commit 2ce7227

5 files changed

Lines changed: 15 additions & 19 deletions

File tree

addons/source-python/packages/source-python/core/cache.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99

1010
# =============================================================================
11-
# >> FORWARD IMPORTS
11+
# >> IMPORTS
1212
# =============================================================================
1313
# Python Imports
1414
# FuncTools
1515
from functools import wraps
1616
# Types
1717
from types import MethodType
1818

19+
20+
# =============================================================================
21+
# >> FORWARD IMPORTS
22+
# =============================================================================
1923
# Source.Python Imports
2024
# Core
2125
from _core._cache import CachedProperty

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ def __init__(self, index, caching=True):
199199
super().__init__(index)
200200

201201
# Set the entity's base attributes
202-
object.__setattr__(self, '_index', index)
202+
vars(self)['index'] = index
203203

204204
def __hash__(self):
205-
"""Return a hash value based on the entity index."""
205+
"""Return a hash value based on the entity inthandle."""
206206
# Required for sets, because we have implemented __eq__
207207
return hash(self.inthandle)
208208

@@ -231,7 +231,7 @@ def __getattr__(self, attr):
231231
raise AttributeError('Attribute "{0}" not found'.format(attr))
232232

233233
def __setattr__(self, attr, value):
234-
"""Find if the attribute is value and sets its value."""
234+
"""Find if the attribute is valid and sets its value."""
235235
# Is the given attribute a property?
236236
if (attr in super().__dir__() and isinstance(
237237
getattr(self.__class__, attr, None), property)):
@@ -299,14 +299,6 @@ def is_networked(self):
299299
"""
300300
return True
301301

302-
@cached_property
303-
def index(self):
304-
"""Return the entity's index.
305-
306-
:rtype: int
307-
"""
308-
return self._index
309-
310302
@property
311303
def owner(self):
312304
"""Return the entity's owner.

src/core/modules/core/core_cache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
// CCachedProperty class.
3636
//-----------------------------------------------------------------------------
3737
CCachedProperty::CCachedProperty(
38-
object fget=object(), object fset=object(), object fdel=object(), const char *doc=NULL,
38+
object fget=object(), object fset=object(), object fdel=object(), object doc=object(),
3939
bool unbound=false, boost::python::tuple args=boost::python::tuple(), dict kwargs=dict())
4040
{
4141
set_getter(fget);
4242
set_setter(fset);
4343
set_deleter(fdel);
4444

45-
m_szDocString = doc;
45+
m_doc = doc;
4646
m_bUnbound = unbound;
4747

4848
m_args = args;
@@ -317,7 +317,7 @@ CCachedProperty *CCachedProperty::wrap_descriptor(
317317
{
318318
CCachedProperty *pProperty = new CCachedProperty(
319319
descriptor.attr("__get__"), descriptor.attr("__set__"), descriptor.attr("__delete__"),
320-
extract<const char *>(descriptor.attr("__doc__")), unbound, args, kwargs
320+
descriptor.attr("__doc__"), unbound, args, kwargs
321321
);
322322

323323
pProperty->__set_name__(owner, name);

src/core/modules/core/core_cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CCachedProperty
4141
{
4242
public:
4343
CCachedProperty(
44-
object fget, object fset, object fdel, const char *doc, bool unbound,
44+
object fget, object fset, object fdel, object doc, bool unbound,
4545
boost::python::tuple args, dict kwargs
4646
);
4747

@@ -88,7 +88,7 @@ class CCachedProperty
8888
dict m_cache;
8989

9090
public:
91-
const char *m_szDocString;
91+
object m_doc;
9292

9393
boost::python::tuple m_args;
9494
dict m_kwargs;

src/core/modules/core/core_cache_wrap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void export_cached_property(scope _cache)
5454
{
5555
class_<CCachedProperty, CCachedProperty *> CachedProperty(
5656
"CachedProperty",
57-
init<object, object, object, const char *, bool, boost::python::tuple, dict>(
57+
init<object, object, object, object, bool, boost::python::tuple, dict>(
5858
(
5959
arg("self"), arg("fget")=object(), arg("fset")=object(), arg("fdel")=object(), arg("doc")=object(),
6060
arg("unbound")=false, arg("args")=boost::python::tuple(), arg("kwargs")=dict()
@@ -216,7 +216,7 @@ void export_cached_property(scope _cache)
216216

217217
CachedProperty.def_readwrite(
218218
"__doc__",
219-
&CCachedProperty::m_szDocString,
219+
&CCachedProperty::m_doc,
220220
"Documentation string for this property.\n"
221221
"\n"
222222
":rtype:\n"

0 commit comments

Comments
 (0)