Skip to content

Comments

fix: rename prompt() to safe_prompt() to avoid module shadowing#483

Open
Sevrain1 wants to merge 2 commits intotmbo:masterfrom
Sevrain1:fix/module-shadowing
Open

fix: rename prompt() to safe_prompt() to avoid module shadowing#483
Sevrain1 wants to merge 2 commits intotmbo:masterfrom
Sevrain1:fix/module-shadowing

Conversation

@Sevrain1
Copy link

What is the problem that this PR addresses?

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 forced "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 expected module.
This is especially an issue when patching prompt module functions in any unit test.

How did you solve it?

This commit renames the prompt() function to safe_prompt() to prevent name shadowing, and to match the naming style of its unsafe_prompt() sister function. It also updates the docs and the examples with the revised name.

Checklist

  • I have read the Contributor's Guide.
  • I will check that all automated PR checks pass before the PR gets reviewed.

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.
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.

1 participant