PHANTOM
🇮🇳 IN
Skip to content

Fix get_caller_name#2672

Merged
T4rk1n merged 3 commits intodevfrom
fix-get-name
Oct 26, 2023
Merged

Fix get_caller_name#2672
T4rk1n merged 3 commits intodevfrom
fix-get-name

Conversation

@T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Oct 25, 2023

Fix get_caller_name by always taking the third stack frame from the function call. (0 is get_caller_name, __init__ is 1 then next one is the app = Dash() call)

@T4rk1n T4rk1n requested a review from alexcjohnson as a code owner October 25, 2023 19:19
@T4rk1n
Copy link
Contributor Author

T4rk1n commented Oct 25, 2023

Taking by index doesn't work in the case of a custom dash class.

Think we can do with a check on the function name, it is get_caller then a chain of __init__ and we are looking for <module> which has a name.

Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 This looks good to me!

Note that there's at least one case where this can give a different result from app = Dash(__name__): if you create app in a function that you call from a different module. The inferred root will be the last time you were at the module scope before calling a function. You could construct some very strange situations here - a function imports a module, and that module calls a function that creates the dash app... but it feels to me as though in all those situations you should really be passing in __name__ from the user code anyway, so what you have is the right solution.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Oct 26, 2023

but it feels to me as though in all those situations you should really be passing in name

Yes I think in those cases you would want to give what is appropriate by either passing the __name__ from the module or in a function argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants