Skip to content

No error for implicitly defined return value #1869

Closed

Description

@shreydesai

Correct me if this issue has already been addressed, but I found the no error for an implicitly defined return value troubling. It seems as if this would not be static typing because the return value should explicitly defined (whatever it is) for statically typed languages.

I think there should be a difference between these two functions when run through the parser, in that the second one should raise an error for not having an explicitly defined return value:

def f() -> None:
    print('Hello world')

def g():
    print('Hello world')

In statically typed languages like Java, return values must be explicitly defined, whether they are void, Strings, or primitive data types, for instance:

public void test1() {
  System.out.println("Hello world");
}

Activity

  1. gvanrossum commented on Jul 15, 2016

    @gvanrossum
    Member

    Well, one of mypy's fundamental properties is that it doesn't complain about a function that has no annotations. So it really should not complain about the second example (g()) above.

    However the following also is not considered an error, and this is indeed troubling:

    def f() -> int:
        print('Hw')

    We should address this when introducing --strict-optional (which is currently experimental).

  2. gvanrossum commented on Jul 15, 2016

    @gvanrossum
    Member

    See also #1748 which adds a new flag that would check for this kind of error (but still not in unannotated functions).

  3. added this to the milestone on Jul 21, 2016
  4. rwbarton commented on Oct 7, 2016

    @rwbarton
    Contributor

    Perhaps the OP is more interested in something like --disallow-untyped-defs.

  5. gvanrossum commented on Oct 7, 2016

    @gvanrossum
    Member

    Then again maybe this can be labeled as a question and closed?

  6. ddfisher commented on Oct 24, 2016

    @ddfisher
    Collaborator

    #1748 has landed, so I'm going to close this.

  7. modified the milestones: , on Oct 24, 2016
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