Skip to content

Commit 4eca5d2

Browse files
committed
Improve SortedDict.iloc attribute warning performance
1 parent cf8d069 commit 4eca5d2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

sortedcontainers/sorteddict.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@ def __init__(self, *args, **kwargs):
177177
self.bisect_key = _list.bisect_key
178178
self.irange_key = _list.irange_key
179179

180-
# GrantJ 2018-05-21 Temporary fix for improved backwards compatibility
181-
# with V1.
182-
183-
self._iloc = SortedKeysView(self)
184-
185180
self._update(*args, **kwargs)
186181

187182

@@ -203,12 +198,18 @@ def iloc(self):
203198
:func:`SortedDict.keys` instead.
204199
205200
"""
206-
warnings.warn(
207-
'sorted_dict.iloc is deprecated. Use SortedDict.keys() instead.',
208-
DeprecationWarning,
209-
stacklevel=2,
210-
)
211-
return self._iloc
201+
# pylint: disable=attribute-defined-outside-init
202+
try:
203+
return self._iloc
204+
except AttributeError:
205+
warnings.warn(
206+
'sorted_dict.iloc is deprecated.'
207+
' Use SortedDict.keys() instead.',
208+
DeprecationWarning,
209+
stacklevel=2,
210+
)
211+
_iloc = self._iloc = SortedKeysView(self)
212+
return _iloc
212213

213214

214215
def clear(self):

0 commit comments

Comments
 (0)