Skip to content

Introduce an Unknown type #2169

@vladfi1

Description

@vladfi1

This is the same issue as #1835, which was closed -- the given reason was that object can be used instead of Unknown. However, this is not the case. Consider:

class Foo(tp.Generic[T]):
  def bar(self, x: T) -> T:
    ...

  def baz(...):
    ...

I want a type that represents "Foo with unknown T", which I can call baz on but not bar.

foo: Foo[Unknown] = ...
foo.bar(1)  # type error, int cannot be assigned to Unknown
foo.baz()  # works fine because no T is needed

This doesn't work if I use object:

foo: Foo[object] = ...
foo.bar(1)  # typechecks because int is a subtype of object

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions