mkorpela / overrides

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

Errors with @staticmethod #91

Closed alkatar21 closed 2 years ago

alkatar21 commented 3 years ago

The following code generates the following exception:

from overrides import overrides

class MyClass(OtherClass):
    @overrides
    @staticmethod
    def function(data: Dict[str, Any]):
        pass
Traceback (most recent call last): 
  ....
  File "file.py", line 106, in MyClass
    def function(data: Dict[str, Any]):
  File "...\lib\site-packages\overrides\overrides.py", line 88, in overrides
    return _overrides(method, check_signature, check_at_runtime)
  File "...\lib\site-packages\overrides\overrides.py", line 103, in _overrides
    for super_class in _get_base_classes(sys._getframe(3), method.__globals__):
AttributeError: 'staticmethod' object has no attribute '__globals__'

It works the other way around:

from overrides import overrides

class MyClass(OtherClass):
    @staticmethod
    @overrides
    def function(data: Dict[str, Any]):
        pass

I would expect that the order would not matter.

Versions: overrides-6.1.0 typing-utils-0.1.0

alkatar21 commented 2 years ago

This is mentioned in the README so i will close this. I must have overlooked that.