Skip to content

Commit cfc3d4b

Browse files
ArmavicaricardoV94
authored andcommitted
Remove DefaultOrderedDict (dicts are ordered now)
1 parent b3b4033 commit cfc3d4b

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

pytensor/graph/rewriting/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import math
33
import sys
4+
from collections import defaultdict
45
from collections.abc import Iterable, Sequence
56
from functools import cmp_to_key
67
from io import StringIO
@@ -9,7 +10,6 @@
910
from pytensor.configdefaults import config
1011
from pytensor.graph.rewriting import basic as pytensor_rewriting
1112
from pytensor.misc.ordered_set import OrderedSet
12-
from pytensor.utils import DefaultOrderedDict
1313

1414

1515
RewritesType = pytensor_rewriting.GraphRewriter | pytensor_rewriting.NodeRewriter
@@ -23,7 +23,7 @@ class RewriteDatabase:
2323
"""
2424

2525
def __init__(self):
26-
self.__db__ = DefaultOrderedDict(OrderedSet)
26+
self.__db__ = defaultdict(OrderedSet)
2727
self._names = set()
2828
# This will be reset by `self.register` (via `obj.name` by the thing
2929
# doing the registering)

pytensor/utils.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import struct
77
import subprocess
88
import sys
9-
from collections import OrderedDict
10-
from collections.abc import Callable
119
from functools import partial
1210

1311

1412
__all__ = [
1513
"get_unbound_function",
1614
"maybe_add_to_os_environ_pathlist",
17-
"DefaultOrderedDict",
1815
"subprocess_Popen",
1916
"call_subprocess_Popen",
2017
"output_subprocess_Popen",
@@ -376,36 +373,3 @@ def __eq__(self, other):
376373

377374
def __hash__(self):
378375
return hash(type(self))
379-
380-
381-
class DefaultOrderedDict(OrderedDict):
382-
def __init__(self, default_factory=None, *a, **kw):
383-
if default_factory is not None and not isinstance(default_factory, Callable):
384-
raise TypeError("first argument must be callable")
385-
OrderedDict.__init__(self, *a, **kw)
386-
self.default_factory = default_factory
387-
388-
def __getitem__(self, key):
389-
try:
390-
return OrderedDict.__getitem__(self, key)
391-
except KeyError:
392-
return self.__missing__(key)
393-
394-
def __missing__(self, key):
395-
if self.default_factory is None:
396-
raise KeyError(key)
397-
self[key] = value = self.default_factory()
398-
return value
399-
400-
def __reduce__(self):
401-
if self.default_factory is None:
402-
args = tuple()
403-
else:
404-
args = (self.default_factory,)
405-
return type(self), args, None, None, iter(self.items())
406-
407-
def copy(self):
408-
return self.__copy__()
409-
410-
def __copy__(self):
411-
return type(self)(self.default_factory, self)

0 commit comments

Comments
 (0)