Skip to content

Idea: "Incomplete" marker #5613

Closed
Closed
@srittau

Description

@srittau

When creating stubs, we encourage contributors to leave items unannotated instead of using Any. This often works, but there are cases where you have to fall back on Any, for example:

class Foo:
    def bar(self, some_arg, other_arg=None):
        self.a_field = something()
        if some_cond():
            return whatever()
        else:
            return None

In this case the best we can do is:

class Foo:
    a_field: Any
    def bar(self, some_arg, other_arg: Any | None = ...) -> Any | None: ...

In this case it's not clear if Any is used, because there is no better alternative or because this needs better annotations.

Idea: We could introduce an alias for Any in _typeshed, called something like Incomplete, Unknown (my current favorite), Something, Untyped, or Unannotated. This could clearly mark that this argument type still needs work:

class Foo:
    some_arg: Unknown
    def bar(self, some_arg, other_arg: Unknown | None = ...) -> Unknown | None: ...

This has a few advantages:

  • Communicates that the type is not final and will be improved (and narrowed) in the future.
  • Communicates that this particular annotation needs work.
  • Gives us a better overview of the completion of stubs and prevents "lies". (In fact, an idea I have is to produce graphs that shows the completion percentage of stubs over time.)
  • Gives us the ability to grep for Any to find areas where the type system could be improved or where newer type system features could be used.

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