Importing TensorFlow causes argparse_flags.ArgumentParser to fail when specifying an argument_default
kentslaney opened this issue · 3 comments
Basically just the title. This code fails:
import tensorflow as tf
from absl.flags.argparse_flags import ArgumentParser
ArgumentParser(argument_default=42)
Edit: I should clarify, it only fails if tensorflow is imported
Thanks for filing the bug. Looks like argument_default=
simply doesn't work if you have any absl.flags
flag defined. This is because a default=
argument is passed to custom actions when argument_default=
is supplied, but our _FlagAction
and _BooleanFlagAction
don't support it. Since absl.flags use dest=argparse.SUPPRESS and the default value is never seen through the argparse namespace, we can simply add a default=
argument and ignore it.
Is there a workaround?
There isn't a good workaround before we put out a fix, but you could monkey patch these methods to have an extra default=
argument:
abseil-py/absl/flags/argparse_flags.py
Line 240 in 4d8ea27
abseil-py/absl/flags/argparse_flags.py
Line 267 in 4d8ea27