Skip to content

Commit

Permalink
Allow turning off context unrolling for post_generation decorator.
Browse files Browse the repository at this point in the history
  • Loading branch information
m000 committed Jan 3, 2025
1 parent 4209372 commit e933211
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions factory/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,17 @@ def container_attribute(func):
return declarations.ContainerAttribute(func, strict=False)


def post_generation(fun):
return declarations.PostGeneration(fun)
def post_generation(fun=None, unroll_context=True):
"""Post-generation decorator that allows turning context unrolling on/off.
Turning off context unrolling is useful e.g. for passing a LazyFunction as
a post-generation keyword argument.
"""
class PostGeneration(declarations.PostGeneration):
UNROLL_CONTEXT_BEFORE_EVALUATION = unroll_context

def post_generation_(fun):
return PostGeneration(fun)

# Note: fun will be None when the decorator is used with parentheses.
return post_generation_(fun) if fun is not None else post_generation_

0 comments on commit e933211

Please sign in to comment.