Closed
Description
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.