-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
argparse.HelpFormatter subclasses may be broken by 3.14 changes #133653
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
Comments
Let's do this. Would you like to open a PR? I'm also happy to do it. |
Please go ahead. |
Something like prefix_chars = kwargs.get('prefix_chars', '-')
color = kwargs.get('color', False) |
FWIW, Lines 62 to 64 in 0ec8fc8
Lines 157 to 162 in 0ec8fc8
But despite that, subclassing |
How does PR #133668 look? |
I think this is a documentation issue. The only way to fix it reliably is to properly document the Currently the |
As discussed on the PR - doc change is welcome but it is not the only way to fix this. I think we should add a setter method for the new fields so that the signature of We saw two libraries break already, there will be more post release. There is no point repeatedly litigating this with users over the next 3-5 years if we can avoid that with a simple change now. |
There is something similar issue #133745. It is more serious, because the documented contract was changed. For HelpFormatter there is no documented contract. We can apply solution similar to the code that was used before #128308 -- pass only prog to the factory, and set other parameters as private HelpFormatter attributes. This approach has many drawbacks. It still can break custom formatters, and for some users it will only defer breakage fr future versions. In long run, it is better to break the user code now. But we need the documentation to make sure that users will write correct code which will not break in future. |
Ultimately it's up to the 3.14 release manager. |
Well, I have a plan to make the transition smoother, and I'm working on it. |
… argument * Fix TypeError when formatter_class is a custom subclass of HelpFormatter. * Fix TypeError when formatter_class is not a subclass of HelpFormatter and non-standard prefix_char is used. * Fix support of colorizing when formatter_class is not a subclass of HelpFormatter.
There were other issues. Colorizing did not work when |
Skip the help tests for now. Not ideal but it's not too bad and it's not pygments-specific anyway. Bug: python/cpython#133653 Bug: python/cpython#133813 Signed-off-by: Sam James <[email protected]>
Skip the help tests for now. Not ideal but it's not too bad and it's not pygments-specific anyway. Bug: python/cpython#133653 Bug: python/cpython#133813 Signed-off-by: Sam James <[email protected]>
…ent (GH-133813) * Fix TypeError when formatter_class is a custom subclass of HelpFormatter. * Fix TypeError when formatter_class is not a subclass of HelpFormatter and non-standard prefix_char is used. * Fix support of colorizing when formatter_class is not a subclass of HelpFormatter. * Remove the prefix_chars parameter of HelpFormatter.
… argument (pythonGH-133813) * Fix TypeError when formatter_class is a custom subclass of HelpFormatter. * Fix TypeError when formatter_class is not a subclass of HelpFormatter and non-standard prefix_char is used. * Fix support of colorizing when formatter_class is not a subclass of HelpFormatter. * Remove the prefix_chars parameter of HelpFormatter. (cherry picked from commit 734e15b) Co-authored-by: Serhiy Storchaka <[email protected]>
I implemented this solution. Also, for now, there is no need to pass |
…s argument (GH-133813) (GH-133941) * Fix TypeError when formatter_class is a custom subclass of HelpFormatter. * Fix TypeError when formatter_class is not a subclass of HelpFormatter and non-standard prefix_char is used. * Fix support of colorizing when formatter_class is not a subclass of HelpFormatter. * Remove the prefix_chars parameter of HelpFormatter. (cherry picked from commit 734e15b) Co-authored-by: Serhiy Storchaka <[email protected]>
I came across this trying to run mypy benchmarks. The version I had contained
Which was rewritten in a newer version to:
The changes in #124456 and #132323 can be made without breaking user code, if they accept the new args as **kwargs, extract their values from kwargs if they are there, and continue working as before if not. Is there a good reason not to do this?
Do these changes currently comply with Python's backwards compatibility policy?
Linked PRs
HelpFormatter
#133668The text was updated successfully, but these errors were encountered: