Skip to content

Functions that are actually classes #5145

Closed
@hauntsaninja

Description

@hauntsaninja

@hatal175 has been fixing several typeshed definitions and was recently looking at itertools. Many documented-as-functions in itertools are currently functions in typeshed, but actually classes at runtime, e.g. itertools.count. The proposed change is to make them classes.

Pros:

  1. Makes typeshed consistent with runtime (albeit undocumented facet of the runtime)
  2. Allows users to do things that depend on these being classes, e.g. type checkers will understand isinstance(x, itertools.count) (admittedly rare)

Cons:

  1. Change can cause annoying false positives because type checkers are often strict about redefinition. E.g. Fix Generators typeshed test mypy#10255

My opinion is that we do nothing (except for maybe linking this issue in the allowlists ;-) ), since I think the con has a more real impact than the pros. Curious for others' thoughts?

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