Commit fa1a8d10 authored by Sylvain Gugger's avatar Sylvain Gugger
Browse files

Tentative fix for HFArgumentParser in Python 3.8

parent 2f848519
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
import dataclasses import dataclasses
import json import json
import re
import sys import sys
from argparse import ArgumentParser, ArgumentTypeError from argparse import ArgumentParser, ArgumentTypeError
from enum import Enum from enum import Enum
...@@ -113,7 +114,9 @@ class HfArgumentParser(ArgumentParser): ...@@ -113,7 +114,9 @@ class HfArgumentParser(ArgumentParser):
kwargs["nargs"] = "?" kwargs["nargs"] = "?"
# This is the value that will get picked if we do --field_name (without value) # This is the value that will get picked if we do --field_name (without value)
kwargs["const"] = True kwargs["const"] = True
elif hasattr(field.type, "__origin__") and issubclass(field.type.__origin__, List): elif (
hasattr(field.type, "__origin__") and re.search(r"^typing\.List\[(.*)\]$", str(field.type)) is not None
):
kwargs["nargs"] = "+" kwargs["nargs"] = "+"
kwargs["type"] = field.type.__args__[0] kwargs["type"] = field.type.__args__[0]
assert all( assert all(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment