aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2012-01-12 08:59:36 -0700
committerCarl Meyer <carl@oddbird.net>2012-01-12 08:59:36 -0700
commit8aec45386aaf410a36bdf57ebf24cfe9f1fdf3b2 (patch)
tree8bb384939f0a90eb07fceb406d5648f56a68d481
parentbf57308c9dcc2d96161993026e138ec181550653 (diff)
downloadfactory-boy-8aec45386aaf410a36bdf57ebf24cfe9f1fdf3b2.tar
factory-boy-8aec45386aaf410a36bdf57ebf24cfe9f1fdf3b2.tar.gz
Clarify extended if check in DeclarationDict.update_with_public.
-rw-r--r--factory/containers.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/factory/containers.py b/factory/containers.py
index 0218e47..847b2c0 100644
--- a/factory/containers.py
+++ b/factory/containers.py
@@ -104,6 +104,20 @@ class LazyStub(object):
class DeclarationDict(dict):
"""Slightly extended dict to work with OrderedDeclaration."""
+ def is_declaration(self, name, value):
+ """Determines if a class attribute is a field value declaration.
+
+ Based on the name and value of the class attribute, return ``True`` if
+ it looks like a declaration of a default field value, ``False`` if it
+ is private (name starts with '_') or a classmethod or staticmethod.
+
+ """
+ if isinstance(value, classmethod):
+ return False
+ elif isinstance(value, declarations.OrderedDeclaration):
+ return True
+ return (not name.startswith("_"))
+
def update_with_public(self, d):
"""Updates the DeclarationDict from a class definition dict.
@@ -114,10 +128,10 @@ class DeclarationDict(dict):
"""
remaining = {}
for k, v in d.iteritems():
- if isinstance(v, classmethod) or k.startswith('_') and not isinstance(v, declarations.OrderedDeclaration):
- remaining[k] = v
- else:
+ if self.is_declaration(k, v):
self[k] = v
+ else:
+ remaining[k] = v
return remaining
def copy(self, extra=None):