crossbario / crossbario/autobahn-python

Special error/warning for generator-methods on API overrides?

Open
#610 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-discussion
Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

See also https://github.com/crossbario/txaio/issues/56

It is easy to forget to add @coroutine or @inlineCallbacks and accidentally get a generator-function instead of a Deferred/Future-returning function (i.e. if you put a yield in the method). Since there's no way that an actual generator-function will work correctly for onJoin and friends, it would be nice if Autobahn detected this and raised an error. I think this is a good idea.

There's a further argument (in the above-linked txaio ticket) that maybe this should apply to any and all functions passed to txaio.as_future (with some way to opt-out on a per-invocation basis). I'm not necessarily sold on this, but it's also very rare to actually want to pass a generator back from an async method -- however, this would have effects on downstream authors (e.g. those who do want to actually pass a generator back) as they'd have to a) know about txaio; and b) use txaio's decorator to "opt out" of the error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how API overrides such as onJoin and other async methods are handled, then review the interaction with txaio.as_future and the @coroutine or @inlineCallbacks decorators. The desired result is an explicit error when an override returns an actual generator instead of a Deferred or Future, with the scope and opt-out behavior resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.