Skip to content

Comment on Super Simple Mocking For Pythonparent

Comments

Yes, the most pythonic is:

  mock(obj, x=1, y=2)
Which you get by:
  def __init__(self, obj, **mocks):
      self.obj = obj
      self.mocks = mocks
This can then also be called (using the built-in double-star-unpacking feature) as:
  mock(obj, **{'x': 1, 'y': 2})
or even
  mock(obj, **dict([('x', 1), ('y', 2)]))
Then there’s no explicit need to support multiple alternative function signatures, and in particular you don’t get people using the (quite atypical and therefore semantically ambiguous):
  mock(obj, 'x', 1, 'y', 2).
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.