diff options
author | Richard Levasseur <rlevasseur@google.com> | 2018-05-31 13:06:49 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-31 13:07:03 -0700 |
commit | b7f621c5ab8827bc20feb7ac13ae746c19b78c9f (patch) | |
tree | 1c99142c8407708e9204a01757ca7014148d1d46 /absl/app.py | |
parent | 7edfc4cb6f83d23b3a7031e9489cae024552bd4c (diff) | |
download | absl-py-b7f621c5ab8827bc20feb7ac13ae746c19b78c9f.tar.gz |
Allow unicode strings in flag help when used with --helpfull.
Previously, the full help output was gotten by calling str(FLAGS), which did
two things: invoke FLAGS.__str__, which returned a unicode object, and then
make str() try to coerce the unicode object to a byte string, which only worked
if the default encoding and text were compatible.
Rather than coerce the object to a string, just call the get_help() method
directly (which is what FLAGS.__str__ invokes). This avoids any coercion
behaviors.
Whether the unicode text can be printed is still subject to the output stream's
encoding, but thats outside absl's purview: users should configure their
environment to be compatible with unicode as appropriate.
NOTE: One oddity of unicode support with flags is that the default value
for a flag doesn't get printed quite correctly due to repr() being called
on the unicode value: this results in an escaped unicode string (u'\uxxx')
up in the help output instead of the value as expected to be passed on the
command line. That's pre-existing, doesn't break anything, and out of scope.
* Also improves the error messages of failed app_test helper invocations.
PiperOrigin-RevId: 198766828
Diffstat (limited to 'absl/app.py')
-rw-r--r-- | absl/app.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/absl/app.py b/absl/app.py index ef2ee67..2dd9c71 100644 --- a/absl/app.py +++ b/absl/app.py @@ -339,7 +339,7 @@ def usage(shorthelp=False, writeto_stdout=False, detailed_error=None, if shorthelp: flag_str = FLAGS.main_module_help() else: - flag_str = str(FLAGS) + flag_str = FLAGS.get_help() try: stdfile.write(doc) if flag_str: |