Skip to content

type hint handling #4

Open
Open
@buhman

Description

@buhman

I tried to autofunction this function:

QueueItem = Union[asyncio.Future, str]

# the expansion of `Optional` makes me realize that `wait: bool=False` is probably more correct

async def pump_queue(queue: Deque[QueueItem], wait: Optional[bool]=False) -> AsyncGenerator[str, None]:
    """
    foo

    Args:
        queue (Deque[QueueItem]):
        wait (Optional[bool]):

    Returns:
        AsyncGenerator[str, None]:
    """

Result:

foo


There are a few problems with this:

  • PEP 484 type hints using typing module are awful to read sphinx-doc/sphinx#3570
  • the docstring parser doesn't interpret types at all (QueueItem isn't expanded like it is in the function definition)
  • the type hints already give us enough information to build args, returns, etc… so it might be smarter to ignore/combine the types from the docstring when type hints are present.
  • Returns: AsyncGenerator[…] is probably more accurate than saying this yields, but I'm not sure.
  • it's uglier than the source code

Do you have any ideas on how/if return types should be reconciled with the implied return types from the await and async for … prefixes that sphinxcontrib-trio adds?

Is PEP484 and/or modifying docstring parsing behavior in-scope for this extension at all?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions