[Yt-svn] yt: As per http://docs.python.org/reference/datamodel.html , __n...
hg at spacepope.org
hg at spacepope.org
Wed Dec 1 08:21:13 PST 2010
hg Repository: yt
details: yt/rev/be4139c3f9c2
changeset: 3561:be4139c3f9c2
user: Matthew Turk <matthewturk at gmail.com>
date:
Wed Dec 01 08:21:09 2010 -0800
description:
As per http://docs.python.org/reference/datamodel.html , __new__ should return
a class that has not had __init__ called. This is why parameter files are
almost always double-instantiated. I have now moved the check_pf call to
inside the StaticOutput constructor, which should occur after
_parse_parameter_file and after the other states that it relies on have been
set. This could result in two possible errors: check_pf could raise an
uncaught exception, or pickling could change. I do not believe either of these
to be likely, and I have tested with the datasets I currently possess.
diffstat:
yt/data_objects/static_output.py | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
diffs (33 lines):
diff -r 20f28b6d9117 -r be4139c3f9c2 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py Sat Nov 27 07:52:28 2010 -0700
+++ b/yt/data_objects/static_output.py Wed Dec 01 08:21:09 2010 -0800
@@ -57,13 +57,7 @@
if not os.path.exists(apath): raise IOError(filename)
if apath not in _cached_pfs:
obj = object.__new__(cls)
- obj.__init__(filename, *args, **kwargs)
_cached_pfs[apath] = obj
- if ytcfg.getboolean('yt','serialize'):
- try:
- _pf_store.check_pf(obj)
- except NoParameterShelf:
- pass
return _cached_pfs[apath]
def __init__(self, filename, data_style=None):
@@ -83,7 +77,14 @@
self.parameters = {}
self._parse_parameter_file()
self._set_units()
- # These can be taken out if you so desire
+ # Because we need an instantiated class to check the pf's existence in
+ # the cache, we move that check to here from __new__. This avoids
+ # double-instantiation.
+ if ytcfg.getboolean('yt','serialize'):
+ try:
+ _pf_store.check_pf(obj)
+ except NoParameterShelf:
+ pass
def __reduce__(self):
args = (self._hash(),)
More information about the yt-svn
mailing list