Decorator of a nested function [Python]

Viewed 286

I'm writing a simple program using threading and sockets. I have created a decorated function with some nested functions inside. They look like this:

class Some_class(object):

    class Decorators(object):

        @classmethod
        def some_decorator(cls, function):
            def inner_function():
                # some_decorations
                pass
            return inner_function

    def __init__(self):
        # some code
        pass

    @Decorators.some_decorator
    def function(self):

        def nested1():
            # some code
            pass

        def nested2():
            # some code
            pass

I've written the nested1 and nested2 as nested functions just because I found usefull to have some better code-organization. I have defined the some_decorator in a nested class inside an existing one as I saw from this link: https://medium.com/@vadimpushtaev/decorator-inside-python-class-1e74d23107f6. I tryied to decorate the nested functions as well, but I have got an error that says: NameError: name 'Decorators' is not defined. Are there any solutions?

Thank you very much for your time and excuse my English, I'm still practising it!

0 Answers
Related