kopia lustrzana https://github.com/micropython/micropython-lib
collections.defaultdict: Make __missing__() behavior more compliant.
https://docs.python.org/3.3/library/collections.html#collections.defaultdict.__missing__ says that it's __missing__() what should check default_factory for None (so this entire behavior can be overriden in subclasses).pull/118/head
rodzic
2d8fde40a4
commit
53f454261b
|
@ -8,8 +8,6 @@ class defaultdict:
|
|||
try:
|
||||
return self.d[key]
|
||||
except KeyError:
|
||||
if self.default_factory is None:
|
||||
raise
|
||||
v = self.__missing__(key)
|
||||
self.d[key] = v
|
||||
return v
|
||||
|
@ -21,4 +19,6 @@ class defaultdict:
|
|||
del self.d[key]
|
||||
|
||||
def __missing__(self, key):
|
||||
if self.default_factory is None:
|
||||
raise KeyError(key)
|
||||
return self.default_factory()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from distutils.core import setup
|
||||
|
||||
setup(name='micropython-collections.defaultdict',
|
||||
version='0.1',
|
||||
version='0.2',
|
||||
description='collections.defaultdict module for MicroPython',
|
||||
url='https://github.com/micropython/micropython/issues/405',
|
||||
author='Paul Sokolovsky',
|
||||
|
|
Ładowanie…
Reference in New Issue