mkorpela / overrides

A decorator to automatically detect mismatch when overriding a method
Apache License 2.0
261 stars 32 forks source link

`sub_return` is required if `super_return` is specified #83

Closed ashwin153 closed 2 years ago

ashwin153 commented 3 years ago

Currently, subclasses are required to have a return type-hint if the superclass defines one.

import overrides

class SuperClass(overrides.EnforceOverrides):
    def foo(self) -> int:
        return 1

class SubClass(SuperClass):
    @overrides.overrides
    def foo(self):
        return 2

# TypeError: SubClass.foo: return type `None` is not a `<class 'int'>`.

This is because and sub_return is not None is missing on the following line.

https://github.com/mkorpela/overrides/blob/deb0f3f291d8797e7f1a8f3137ad6e8e6e3898cf/overrides/signature.py#L286-L288

ashwin153 commented 3 years ago

@mkorpela My bad I created a commit with the intention of creating a PR, but it automatically merged it.

ashwin153 commented 3 years ago

Can you back out my commit and then create a new PR with it (if you don't like the change)? Sorry about that.

ashwin153 commented 3 years ago

https://github.com/mkorpela/overrides/commit/1aede9d4b58010d16ce850689f223713c0be5937

It should be or not and my bad.

ashwin153 commented 3 years ago

Ok backed out the change. Sorry about that.

mkorpela commented 2 years ago

I think this is fine. Closing this issue. Other way is ok: if super return is not specified then sub return can be whatever.