Closed marcoeilers closed 6 years ago
Actually, this might be an instance of a larger problem. I think I remember seeing that we infer a return type that is not None for functions that don't actually return anything. I think we shouldn't do that, they should get type None.
The return type of a function with no return is defined as a super type of None
. The reason for this was to make this program typeable:
class A:
def f(self):
pass
class B(A):
def f(self):
return 1
If the method f
in class A
is restricted to return None, the program will not be typeable due to the variance rules imposed by overriding this method in class B
Can’t we support the @abstractmethod decorator instead?
Done here
Now you can declare a class as abstract by setting its metaclass to ABCMeta
(imported from abc
module), and declare a method as abstract by decorating it with @abstractmethod
.
You now get unsat if you try to instantiate an abstract class.
I also modified some unit tests to adapt to this change.
Don't we need to also modify the projects like imp?
I did
In Mypy, constructor return types are always None (https://github.com/python/mypy/issues/604), but we seem to infer the type of the class as the return type instead? Or maybe we infer arbitrary types and I just happened to get the type of the class as the return type? Either way, it should be None instead.