fix: rename prompt() to safe_prompt() to avoid module shadowing#483
Open
Sevrain1 wants to merge 2 commits intotmbo:masterfrom
Open
fix: rename prompt() to safe_prompt() to avoid module shadowing#483Sevrain1 wants to merge 2 commits intotmbo:masterfrom
Sevrain1 wants to merge 2 commits intotmbo:masterfrom
Conversation
The `questionary.prompt.prompt` function has the same name as its parent module. This, together with the `from questionary.prompt import prompt` line in the package's `__init__.py` file, causes the `questionary.prompt` module to be shadowed by its `prompt()` function. This built-in "shadowing" prevents the `prompt` module from being properly imported, as any `from questionary import prompt` statement will incorrectly import the `prompt.prompt` function instead of the required module. This is especially an issue when patching `prompt` module functions in unit tests. This commit renames the `prompt()` function to `safe_prompt()`, to prevent name shadowing and to match the naming style on its `unsafe_prompt()` sister function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the problem that this PR addresses?
The
questionary.prompt.promptfunction has the same name as its parent module. This, together with thefrom questionary.prompt import promptline in the package's__init__.pyfile, causes thequestionary.promptmodule to be shadowed by itsprompt()function.This forced "shadowing" prevents the
promptmodule from being properly imported, as anyfrom questionary import promptstatement will incorrectly import theprompt.promptfunction instead of the expected module.This is especially an issue when patching
promptmodule functions in any unit test.How did you solve it?
This commit renames the
prompt()function tosafe_prompt()to prevent name shadowing, and to match the naming style of itsunsafe_prompt()sister function. It also updates the docs and the examples with the revised name.Checklist