Skip to content

No error for implicitly defined return value #1869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shreydesai opened this issue Jul 15, 2016 · 5 comments
Closed

No error for implicitly defined return value #1869

shreydesai opened this issue Jul 15, 2016 · 5 comments

Comments

@shreydesai
Copy link
Contributor

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");
}
@gvanrossum
Copy link
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).

@gvanrossum
Copy link
Member

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

@rwbarton
Copy link
Contributor

rwbarton commented Oct 7, 2016

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

@gvanrossum
Copy link
Member

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

@ddfisher
Copy link
Collaborator

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

@ddfisher ddfisher modified the milestones: Questions, 0.5 Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants