Jordan Mirocha avatar Jordan Mirocha committed 2d27d57

Only modify kwargs if f.__name__ == __call__.

Comments (0)

Files changed (1)

pyspeckit/spectrum/config.py

     def decorator(self, *args, **kwargs):    
         all_args, all_vars, all_keys, all_defs = inspect.getargspec(f)                
         all_args.pop(0) # pop self
-                                                                                                                       
-        new_kwargs = {}
-        for i, default in enumerate(all_defs):
-            if mycfg.has_key(all_args[i]): new_kwargs[all_args[i]] = mycfg[all_args[i]]
-            else: new_kwargs[all_args[i]] = default
+                                          
+        argsdefs = {}
+        for i, arg in enumerate(all_args):
+            argsdefs[arg] = all_defs[i]
+                                                                   
+        # Include all supplied keyword arguments                                                                                                               
+        new_kwargs = argsdefs
+        
+        # Read in config file
+        for arg in new_kwargs:
+            if mycfg.has_key(arg): new_kwargs[arg] = mycfg[arg]
+                
+        # Has anything changed?
+        if f.__name__ == '__call__':
+            for arg in kwargs:
+                try: 
+                    if kwargs[arg] != argsdefs[arg]: new_kwargs[arg] = kwargs[arg]
+                except KeyError: 
+                    new_kwargs[arg] = kwargs[arg]
+                
+                       
+                        
+        # Add all those from config file
+       # for i, default in enumerate(all_defs):
+       #     if new_kwargs.has_key(all_args[i]): continue
+       #     
+       #     if mycfg.has_key(all_args[i]): new_kwargs[all_args[i]] = mycfg[all_args[i]]
+       #     else: new_kwargs[all_args[i]] = default
             
             # Only update parameter value if it isn't equal to its default...not sure this is absolutely correct
-            if kwargs.has_key(all_args[i]): 
-                if kwargs[all_args[i]] != all_defs[i]:
-                    new_kwargs[all_args[i]] = kwargs[all_args[i]]          
+            #if kwargs.has_key(all_args[i]): 
+            #    if kwargs[all_args[i]] != all_defs[i]:
+            #        new_kwargs[all_args[i]] = kwargs[all_args[i]]          
                                                                                                                
         f(self, *args, **new_kwargs)
             
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.