Skip to content

Commit

Permalink
Merge pull request #3190 from mwichmann/stdlib-OrderedDict
Browse files Browse the repository at this point in the history
Stop using custom OrderedDict
  • Loading branch information
bdbaddog authored Sep 20, 2018
2 parents f4821b9 + a2e3ec1 commit 3fa7141
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 68 deletions.
3 changes: 2 additions & 1 deletion src/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE
time.clock deprecated since py3.3, due to remove in 3.8. deprecation
warnings from py3.7 were failing a bunch of tests on Windows since they
mess up expected stderr.
- tar packaging test fixups
- Remove obsoleted internal implementaiton of OrderedDict.
- Test for tar packaging fixups

From Hao Wu
- typo in customized decider example in user guide
Expand Down
3 changes: 2 additions & 1 deletion src/engine/SCons/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import subprocess
import itertools
import inspect
from collections import OrderedDict

import SCons.Debug
from SCons.Debug import logInstanceCreation
Expand Down Expand Up @@ -1294,7 +1295,7 @@ def get_implicit_deps(self, target, source, env):
return result

def get_varlist(self, target, source, env, executor=None):
result = SCons.Util.OrderedDict()
result = OrderedDict()
for act in self.list:
for var in act.get_varlist(target, source, env, executor):
result[var] = True
Expand Down
3 changes: 2 additions & 1 deletion src/engine/SCons/Tool/javac.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import os
import os.path
from collections import OrderedDict

import SCons.Action
import SCons.Builder
Expand Down Expand Up @@ -70,7 +71,7 @@ def emit_java_classes(target, source, env):
if isinstance(entry, SCons.Node.FS.File):
slist.append(entry)
elif isinstance(entry, SCons.Node.FS.Dir):
result = SCons.Util.OrderedDict()
result = OrderedDict()
dirnode = entry.rdir()
def find_java_files(arg, dirpath, filenames):
java_files = sorted([n for n in filenames
Expand Down
74 changes: 9 additions & 65 deletions src/engine/SCons/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@
PY3 = sys.version_info[0] == 3

try:
from collections import UserDict, UserList, UserString
except ImportError:
from UserDict import UserDict
except ImportError as e:
from collections import UserDict

try:
from UserList import UserList
except ImportError as e:
from collections import UserList

from collections import Iterable
from UserString import UserString

try:
from UserString import UserString
except ImportError as e:
from collections import UserString
from collections.abc import Iterable
except ImportError:
from collections import Iterable

from collections import OrderedDict

# Don't "from types import ..." these because we need to get at the
# types module later to look for UnicodeType.
Expand All @@ -63,7 +60,7 @@
FunctionType = types.FunctionType

try:
unicode
_ = type(unicode)
except NameError:
UnicodeType = str
else:
Expand Down Expand Up @@ -1032,59 +1029,6 @@ def __radd__(self, other):
def __str__(self):
return ' '.join(self.data)

# A dictionary that preserves the order in which items are added.
# Submitted by David Benjamin to ActiveState's Python Cookbook web site:
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
# Including fixes/enhancements from the follow-on discussions.
class OrderedDict(UserDict):
def __init__(self, dict = None):
self._keys = []
UserDict.__init__(self, dict)

def __delitem__(self, key):
UserDict.__delitem__(self, key)
self._keys.remove(key)

def __setitem__(self, key, item):
UserDict.__setitem__(self, key, item)
if key not in self._keys: self._keys.append(key)

def clear(self):
UserDict.clear(self)
self._keys = []

def copy(self):
dict = OrderedDict()
dict.update(self)
return dict

def items(self):
return list(zip(self._keys, list(self.values())))

def keys(self):
return self._keys[:]

def popitem(self):
try:
key = self._keys[-1]
except IndexError:
raise KeyError('dictionary is empty')

val = self[key]
del self[key]

return (key, val)

def setdefault(self, key, failobj = None):
UserDict.setdefault(self, key, failobj)
if key not in self._keys: self._keys.append(key)

def update(self, dict):
for (key, val) in dict.items():
self.__setitem__(key, val)

def values(self):
return list(map(self.get, self._keys))

class Selector(OrderedDict):
"""A callable ordered dictionary that maps file suffixes to
Expand Down

0 comments on commit 3fa7141

Please sign in to comment.