-
Notifications
You must be signed in to change notification settings - Fork 183
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
[Python APIView] display decorators on models #4860
Comments
@annatisch @johanste so the issue here is that Python APIView renders essentially the "compiled" Python, meaning that when we are inspecting the live Python objects, any class decorators have already been applied, and we are seeing the resulting impact of them. Consider this: def get_id(self):
return self.__id
def add_id(cls):
cls_init = cls.__init__
def __init__(self, id, *args, **kwargs):
self.__id = id
self.get_id = get_id
cls_init(self, *args, **kwargs)
cls.__init__ = __init__
return cls
@add_id
class ClassWithDecorators:
pass What do you want to see in APIView? Today you would see the result of # Option 1: render the final result of the applied decorator
class ClassWithDecorators:
def __init__(self, id, *args, **kwargs) I can parse into the source to extract and render the decorator statement, but it will still have the "applied" change to # Option 2: render the "applied" body but still annotate the decorators
@add_id
class ClassWithDecorators:
def __init__(self, id, *args, **kwargs) To render it as it is in source I would either need to somehow "subtract" the applied # Option 3: render how it appears in source
@add_id
class ClassWithDecorators:
pass |
From @annatisch
The text was updated successfully, but these errors were encountered: