From 8dfd39ea5ca96855bf0bb39c046cced378210b0d Mon Sep 17 00:00:00 2001 From: Michael Wu Date: Tue, 14 Jan 2020 17:41:35 -0800 Subject: [PATCH] Fix get config fields for Pytext documentation Summary: pytext gen-default-config was failing with recursion, turns out getting "Config" attribute isn't visible with dir(obj) but is with hasattr(obj, "Config"). Also tiny fix for a null "include_dirs" when trying to run the output config. Reviewed By: hudeven Differential Revision: D19397681 fbshipit-source-id: bd78da808e32c43019154aa1895179dbc6252bf7 --- pytext/main.py | 2 +- pytext/utils/documentation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytext/main.py b/pytext/main.py index 4614dd103..a539a67f3 100644 --- a/pytext/main.py +++ b/pytext/main.py @@ -215,7 +215,7 @@ def load_config(): eprint("No config file specified, reading from stdin") config = json.load(sys.stdin) # before parsing the config, include the custom components - for path in config.get("include_dirs", []): + for path in config.get("include_dirs", None) or []: add_include(path.rstrip("/")) context.obj.config = parse_config(config) return context.obj.config diff --git a/pytext/utils/documentation.py b/pytext/utils/documentation.py index 5e86bd7bf..362988c78 100644 --- a/pytext/utils/documentation.py +++ b/pytext/utils/documentation.py @@ -17,7 +17,7 @@ def get_class_members_recursive(obj): """Find all the field names for a given class and their default value.""" - ret = dict(vars(obj.Config if "Config" in dir(obj) else obj)) + ret = dict(vars(obj.Config if hasattr(obj, "Config") else obj)) for b in getattr(obj, "__bases__", []): # Only pytext configs. # Exclude Module because it adds load_path and save_path.