[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-06 Thread Luca
Luca added the comment: The issue has been fixed in `typeshed`, so the following is now allowed: width = min(80, shutil.get_terminal_size().columns - 2) formatter_class = lambda prog: argparse.RawDescriptionHelpFormatter(prog, width=width)

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-04 Thread Luca
Luca added the comment: I opened two issues regarding the mypy error, I understand it is going to be fixed in typeshed: https://github.com/python/mypy/issues/8487 https://github.com/python/typeshed/issues/3806 -- ___ Python tracker

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-03 Thread Luca
Luca added the comment: Of course I still think there should be an easier way to do this though. -- ___ Python tracker ___ ___

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-02 Thread Luca
Luca added the comment: For the benefit of other developers willing to control text width with `argparse`, using the lambda function let `mypy` fail with the following error: 541: error: Argument "formatter_class" to "ArgumentParser" has incompatible type "Callable[[Any],

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-02 Thread Luca
Luca added the comment: OK, I will do this for my package, but I do not believe many others will do the same without a `max_text_width` parameter (too much care is needed for this to work correctly), and as a result most packages using `argparse` will continue to not properly handle text

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-02 Thread paul j3
paul j3 added the comment: But you can replace the simple 'lambda' with a function that takes the max with 'columns'. In other words, include: width = _shutil.get_terminal_size().columns width -= 2 width = min(max_text_width, width) The only thing

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-02 Thread Luca
Luca added the comment: That lambda function would not give the same result, as it would constrain the text width to a fixed value, while my proposal would just set a maximum limit (if the terminal is narrower, the actual text width would be reduced). With the current implementation all

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I don't like the idea of adding more parameters to > the `ArgumentParser` class. It's too complicated already. I concur with Paul. Let's pass on this suggestion. -- resolution: -> rejected stage: -> resolved status: open -> closed

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-01 Thread paul j3
paul j3 added the comment: https://bugs.python.org/issue13041 is (I think) the latest issue/patch to deal with the help width. I don't like the idea of adding more parameters to the `ArgumentParser` class. It's too complicated already. There are a couple of ways that a user can do this

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-01 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +paul.j3, rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue39809] argparse: add max_text_width parameter to ArgumentParser

2020-03-01 Thread Luca
New submission from Luca : It is often desirable to limit the help text width, for instance to 78 or 88 columns, regardless of the actual size of the terminal window. Currently you can achieve this in rather cumbersome ways, for instance by setting "os.environ['COLUMNS'] = '80'" (but this