提交 cfc3d4b6 authored 作者: Virgile Andreani's avatar Virgile Andreani 提交者: Ricardo Vieira

Remove DefaultOrderedDict (dicts are ordered now)

上级 b3b4033d
import copy import copy
import math import math
import sys import sys
from collections import defaultdict
from collections.abc import Iterable, Sequence from collections.abc import Iterable, Sequence
from functools import cmp_to_key from functools import cmp_to_key
from io import StringIO from io import StringIO
...@@ -9,7 +10,6 @@ from typing import Union ...@@ -9,7 +10,6 @@ from typing import Union
from pytensor.configdefaults import config from pytensor.configdefaults import config
from pytensor.graph.rewriting import basic as pytensor_rewriting from pytensor.graph.rewriting import basic as pytensor_rewriting
from pytensor.misc.ordered_set import OrderedSet from pytensor.misc.ordered_set import OrderedSet
from pytensor.utils import DefaultOrderedDict
RewritesType = pytensor_rewriting.GraphRewriter | pytensor_rewriting.NodeRewriter RewritesType = pytensor_rewriting.GraphRewriter | pytensor_rewriting.NodeRewriter
...@@ -23,7 +23,7 @@ class RewriteDatabase: ...@@ -23,7 +23,7 @@ class RewriteDatabase:
""" """
def __init__(self): def __init__(self):
self.__db__ = DefaultOrderedDict(OrderedSet) self.__db__ = defaultdict(OrderedSet)
self._names = set() self._names = set()
# This will be reset by `self.register` (via `obj.name` by the thing # This will be reset by `self.register` (via `obj.name` by the thing
# doing the registering) # doing the registering)
......
...@@ -6,15 +6,12 @@ import os ...@@ -6,15 +6,12 @@ import os
import struct import struct
import subprocess import subprocess
import sys import sys
from collections import OrderedDict
from collections.abc import Callable
from functools import partial from functools import partial
__all__ = [ __all__ = [
"get_unbound_function", "get_unbound_function",
"maybe_add_to_os_environ_pathlist", "maybe_add_to_os_environ_pathlist",
"DefaultOrderedDict",
"subprocess_Popen", "subprocess_Popen",
"call_subprocess_Popen", "call_subprocess_Popen",
"output_subprocess_Popen", "output_subprocess_Popen",
...@@ -376,36 +373,3 @@ class Singleton: ...@@ -376,36 +373,3 @@ class Singleton:
def __hash__(self): def __hash__(self):
return hash(type(self)) return hash(type(self))
class DefaultOrderedDict(OrderedDict):
def __init__(self, default_factory=None, *a, **kw):
if default_factory is not None and not isinstance(default_factory, Callable):
raise TypeError("first argument must be callable")
OrderedDict.__init__(self, *a, **kw)
self.default_factory = default_factory
def __getitem__(self, key):
try:
return OrderedDict.__getitem__(self, key)
except KeyError:
return self.__missing__(key)
def __missing__(self, key):
if self.default_factory is None:
raise KeyError(key)
self[key] = value = self.default_factory()
return value
def __reduce__(self):
if self.default_factory is None:
args = tuple()
else:
args = (self.default_factory,)
return type(self), args, None, None, iter(self.items())
def copy(self):
return self.__copy__()
def __copy__(self):
return type(self)(self.default_factory, self)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论