Skip to content

Maybe recommend using ellipsis as function body in stubs #109

@JukkaL

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.

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