facebook/TestSlide

Simplify sharing contexts at top level

开放

#13 创建于 2019年4月5日

 (2 条评论) (0 个反应) (0 位负责人)Python (58 个派生)auto 404
TestSlide DSLenhancementhelp wanted

仓库指标

星标
 (147 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

If we have a shared context defined in one file:

def some_shared_context(context):
  @context.before
  def before(self):
    pass

and we want to use it at different files, we need to do this:

from wherever import some_shared_context

@context
def first(context):
  context.shared_context(some_shared_context)
  context.merge_context("some shared context")

and on the other file:

from wherever import some_shared_context

@context
def second(context):
  context.shared_context(some_shared_context)
  context.merge_context("some shared context")

We can somewhat easily modify the merge_context function to accept the function directly, simplifying things:

from wherever import some_shared_context

@context
def first(context):
  context.merge_context(some_shared_context)

and on the other file

from wherever import some_shared_context

@context
def second(context):
  context.merge_context(some_shared_context)

贡献者指南