Skip to content

Maybe recommend using ellipsis as function body in stubs #109

Closed

Description

@JukkaL

Instead of using pass as a function body in stubs, maybe we should recommend using ... (literal ellipsis) instead.

Here is an example adapted to use this style (from fnmatch in mypy stubs):

def fnmatch(name: AnyStr, pat: AnyStr) -> bool: ...
def fnmatchcase(name: AnyStr, pat: AnyStr) -> bool: ...
def filter(names: Iterable[AnyStr], pat: AnyStr) -> List[AnyStr]: ...
def translate(pat: str) -> str: ...

This would be consistent with other uses of ... in stubs:

x = ... # type: int

def f(x: int = ...) -> int: ...

This has the nice property of making stubs look different from most normal Python source code, so it would be less likely that people would mistake the two. The .pyi extension also helps with the ambiguity.

Even if we decide that this is okay, I'm not sure if this needs to be specified in the PEP, as ... and pass are semantically equivalent. This is only a style issue.

Activity

  1. matthiaskramm commented on May 18, 2015

    @matthiaskramm
    Contributor

    I like it. The "pass" statement has always looked odd to me, in stubs. Ellipsis is better, and makes it clear that you're not looking at a normal Python file.

  2. gvanrossum commented on May 18, 2015

    @gvanrossum
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions