Skip to content

return type cannot be awaitable | int? #5629

Answered by hmc-cs-mdrissi
pbelskiy asked this question in Q&A
Discussion options

You must be logged in to vote

I took a light look at ujenkins library and if your approach is having separate adapter classes then generics + overloads could do this. Simplified idea,

AsyncMode = TypeVar('AsyncT', Literal[True, False])
class MainJob(Generic[AsyncMode]):
  @overload
  def __init__(self: MainJob[Literal[True]], adapter: AsyncAdapter):
    ...

  @overload
  def __init__(self: MainJob[Literal[False]], adapter: SyncAdapter):
    ...

  @overload
  def echo(self: MainJob[Literal[True]], message: str) -> Awaitable:
    ...

  @overload
  def echo(self: MainJob[False], message: str) -> int:
    ...

Key trick is adapter determines where MainJob type variable for asyncness is true/false and overloads can be us…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@pbelskiy
Comment options

Comment options

You must be logged in to vote
1 reply
@pbelskiy
Comment options

Answer selected by pbelskiy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants