mirror of
https://github.com/NousResearch/atropos.git
synced 2026-04-19 12:57:58 +00:00
fix bug where None would be parsed as a str instead of special value
This commit is contained in:
parent
a4d8d7e875
commit
ae24b022c3
2 changed files with 53 additions and 31 deletions
|
|
@ -156,24 +156,41 @@ def get_double_dash_flags() -> Dict[str, Any]:
|
|||
|
||||
# Remove '--' prefix
|
||||
key_part = arg[2:]
|
||||
key = ""
|
||||
value_str = (
|
||||
None # Variable to hold the string value before potential conversion
|
||||
)
|
||||
|
||||
# Check for '--key=value' format
|
||||
if "=" in key_part:
|
||||
key, value = key_part.split("=", 1)
|
||||
if key: # Ensure key is not empty (e.g. --=value)
|
||||
flags_dict[key] = value
|
||||
key, value_str = key_part.split("=", 1)
|
||||
if not key: # Ensure key is not empty (e.g. --=value)
|
||||
i += 1
|
||||
continue # Skip if key is empty
|
||||
|
||||
# Process value: Convert "None" string to None object
|
||||
if value_str == "None":
|
||||
flags_dict[key] = None
|
||||
else:
|
||||
flags_dict[key] = value_str
|
||||
i += 1
|
||||
# Check if next argument exists and is a value (doesn't start with '-')
|
||||
elif i + 1 < len(args) and not args[i + 1].startswith("-"):
|
||||
key = key_part
|
||||
value = args[i + 1]
|
||||
flags_dict[key] = value
|
||||
value_str = args[i + 1]
|
||||
|
||||
# Process value: Convert "None" string to None object
|
||||
if value_str == "None":
|
||||
flags_dict[key] = None
|
||||
else:
|
||||
flags_dict[key] = value_str
|
||||
# Skip the next argument since we've consumed it as a value
|
||||
i += 2
|
||||
# Otherwise, treat as a boolean flag
|
||||
else:
|
||||
key = key_part
|
||||
flags_dict[key] = True
|
||||
if key: # Ensure key is not empty (e.g. just '--')
|
||||
flags_dict[key] = True
|
||||
i += 1
|
||||
|
||||
return flags_dict
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue