Skip to content

Accept None as return type #10

Description

@raabf

You should allow to write something like that to indicate there is no return (=void)

@typechecked
def rettest(self) -> None:
    print("Hello World")

But Actually

Hello World
Traceback (most recent call last):
[...]
  File "[...]/annotation/typed.py", line 500, in wrapper
    return _check_return_type(signature, target(*args, **kwargs))
  File "[...]/annotation/typed.py", line 477, in _check_return_type
    raise TypeError('Incorrect return type')
TypeError: Incorrect return type

is thrown and you had to use

@typechecked
def rettest(self) -> type(None):
    print("Hello World")

but writing that is ugly and PEP484 defines that

When used in a type hint, the expression None is considered equivalent to type(None) .

so you should also allow None as type.

This is an alternative to #8 .

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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