Skip to content

Should stubs contain default values? #8988

Closed
@hauntsaninja

Description

@hauntsaninja

This has come up recently, for similar reasons as #4881 and discussed a little there

From @gramster

an advantage of including default values is that tools like pyright or pylance will use stubs (if available) for the signatures they show to users when hovering over a function call, and users want to see the default values. I'd like to understand your point of view though as to why you would prefer them removed?

I'm overall fine with this, though I'd like to see the following:

  • we restrict it to simple literal values (e.g. anything that can go into a Literal)
  • we can still use ... at author's discretion (useful in overloads or cases where value doesn't actually matter or to avoid awful x: Literal["x"] = "x" things)
  • we update e.g. stubtest to verify stuff

The case for:

  • lets IDEs provide more information to users

The case against:

  • most things are longer than ... and terseness may be more valuable than the additional information
  • it's a thing that needs doing and maintaining
  • if we allow complicated default values there are more costs

A similar thing could apply to constants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    project: policyOrganization of the typeshed project

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions