-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Global Arguments stop working in Python 3.9.8 #20269
Comments
@rhettinger @ambv Can you look at this? It looks like a serious regression in 3.9.8. |
Thank you so much @gvanrossum for the prompt response and fix! Really appreciate your help! |
For our own tracking purposes:
|
@ambv, can we get an ETA for the Python 3.9.9 release with the fix? We are seeing Python 3.9.8 deployed to Azure Pipelines and MacOS Homebrew (#20322), which is affecting more and more users. Really appreciate your help. |
For MacOS users: As it is not easy to install old/specific versions of Python (like 3.9.7) on MacOS with brew (Homebrew/discussions#155), we are working with brew team to release Azure CLI on Python 3.10 as soon as possible which is not affected (Homebrew/homebrew-core#86758). For now, as a workaround, you may manually install Python 3.10 and install
|
When using
This is due to the behavior change of default value discussed in python/cpython#28420 (comment) - default value is no longer set before the |
@ambv, can we get an ETA for the Python 3.9.9 release with the fix? We are seeing Python 3.9.8 [deployed to Azure Pipelines](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#python) and MacOS Homebrew (#20322), which is affecting more and more users. Really appreciate your help.
I'm releasing it today.
|
however
still looks broken to me. This used to work. What am I doing wrong? I get the same result if I include a query like in the example:
|
Looks similar to #20125. Though no Python version presented in that issue. I came across the same problem when running May be better to open another issue. |
How should we test it? Thanks! |
Sorry, I'm releasing Python 3.9.9 today, not azure-cli. The fixed Python 3.9.9 release is now available: |
thanks @ambv . Thanks for fixing as all my scripts were breaking before! |
Thanks @ambv, good to know you have released Python 3.9.9 |
SolutionIf you directly use PythonAs Python 3.9.9 has been released, please download and install the latest Python 3.9.9 from https://www.python.org/downloads/. ⚠ You may also use Python 3.10 to install Azure CLI, but be aware that If you use Homebrew on MacOSHomebrew/homebrew-core#86758 has been merged. Please update Azure CLI installation with
⚠ As now the formula uses Python 3.10, |
Symptom
Global Arguments now stop working in Python 3.9.8:
Notice
--query
doesn't take effact.Root cause
This is due to the
argparse
breaking change python/cpython#28420 which aims to solve https://bugs.python.org/issue45235. Python 3.9.8 is the first released version with this change. It will spread to all Python versions later.In Knack, global arguments are registered on all root/intermediate/leaf parsers, and they share the same
dest
. Previously, leaf-level arguments takes precedence. After this change, root-level arguments take precedence.We are not sure if this is intended or not, as according to Semantic Versioning, a PATCH version update shouldn't cause breaking change.
Since Azure CLI does some trimming on the command table, using
--query
on the root parser won't work. We have to use Knack directly to demonstrate it:python .\knack\examples\exapp2 sample-json --query id
python .\knack\examples\exapp2 --query id sample-json
Proposed solution
Knack should only register global arguments on leaf parsers to avoid this issue. We don't allow using global arguments in the middle of a command anyway:
az cloud show --query profile
az --query profile cloud show
az cloud --query profile show
References
This issue is also affecting other CLI tools utilizing
argparse
:argparse
subparser defaults in Python 3.9+ sopel-irc/sopel#2210A related topic for
--output
was extensively discussed before:--output
at top level corrupts subcommand configuration #7877The text was updated successfully, but these errors were encountered: