Skip to content
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

Is there a way to check return type error incompatible with supertype? #81

Closed
HeliWang opened this issue Apr 28, 2018 · 2 comments
Closed
Labels
cat: core core language and typing features enhancement

Comments

@HeliWang
Copy link

For such an example:

from abc import ABCMeta, abstractmethod
from typing import Callable, Type, TypeVar, Any

class A(metaclass=ABCMeta):
    @abstractmethod
    def foo(self, x: int) -> Any: pass

    @abstractmethod
    def bar(self) -> str: pass

class B(A):
    def foo(self, x: int) -> None: ...
    def bar(self) -> int:
        return 1

#a = A()  # Error: A is abstract
b = B()  # OK

Mypy will complain the following error:
a.py:13: error: Return type of "bar" incompatible with supertype "A"

However pytype seems to ignore such an error.
Is there a way to check return type error incompatible with supertype? Thanks.

@martindemello
Copy link
Contributor

No, we currently just check that classes with abstract methods are not being instantiated.

@rchen152 rchen152 added the cat: core core language and typing features label Jan 19, 2021
bperozzi pushed a commit to tensorflow/gnn that referenced this issue Nov 4, 2021
 - Check isinstance(arg, tf.keras.layers.Layer) at runtime.
 - Type annotations refer to Protocols for the call() signature.
   NOTE: This is not checked yet, google/pytype#81.

PiperOrigin-RevId: 405832960
bperozzi pushed a commit to tensorflow/gnn that referenced this issue Nov 4, 2021
 - Check isinstance(arg, tf.keras.layers.Layer) at runtime.
 - Type annotations refer to Protocols for the call() signature.
   NOTE: This is not checked yet, google/pytype#81.

PiperOrigin-RevId: 405832960
@martindemello
Copy link
Contributor

this should now work with the --overriding-return-type-checks flag, and should soon be enabled by defalut.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat: core core language and typing features enhancement
Projects
None yet
Development

No branches or pull requests

3 participants