diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-02 01:33:53 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-03-03 21:38:46 +0100 |
commit | 37621846d541d7afcad52e6dba8281bd1146cf09 (patch) | |
tree | 6b361c8f3b9e9d7d95c5324e08d030a555ecf3fc /factory | |
parent | aecf1b73d9c9d653220b6d8825d5eacd2cb6bd74 (diff) | |
download | factory-boy-37621846d541d7afcad52e6dba8281bd1146cf09.tar factory-boy-37621846d541d7afcad52e6dba8281bd1146cf09.tar.gz |
Deprecate the extract_prefix option to PostGeneration.
Introduces a new, call-less syntax for the @post_generation decorator.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory')
-rw-r--r-- | factory/declarations.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/factory/declarations.py b/factory/declarations.py index d5b7950..83f4d32 100644 --- a/factory/declarations.py +++ b/factory/declarations.py @@ -363,6 +363,11 @@ class PostGenerationDeclaration(object): """ def __init__(self, extract_prefix=None): + if extract_prefix: + warnings.warn( + "The extract_prefix argument to PostGeneration declarations " + "is deprecated and will be removed in the future.", + PendingDeprecationWarning, 3) self.extract_prefix = extract_prefix def extract(self, name, attrs): @@ -410,10 +415,22 @@ class PostGeneration(PostGenerationDeclaration): self.function(obj, create, extracted, **kwargs) -def post_generation(extract_prefix=None): - def decorator(fun): - return PostGeneration(fun, extract_prefix=extract_prefix) - return decorator +def post_generation(*args, **kwargs): + assert len(args) + len(kwargs) <= 1, "post_generation takes at most one argument." + if args and callable(args[0]): + # Called as @post_generation applied to a function + return PostGeneration(args[0]) + else: + warnings.warn( + "The @post_generation should now be applied directly to the " + "function, without parameters. The @post_generation() and " + "@post_generation(extract_prefix='xxx') syntaxes are deprecated " + "and will be removed in the future; use @post_generation instead.", + PendingDeprecationWarning, 2) + extract_prefix = kwargs.get('extract_prefix') + def decorator(fun): + return PostGeneration(fun, extract_prefix=extract_prefix) + return decorator class RelatedFactory(PostGenerationDeclaration): |