You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When retrieving type from field.type, type is a string literal indicating the type rather than the specific type class. Therefore, it cannot be added as type argument for add_argument in argparse as it expects a Callable.
Explanation
This issue arises because type evaluation is deferred when from __future__ import annotations is used.
from __future__ importannotationsclassA:
foo: strA.__annotatiions__# {'foo': 'str'}
Therefore, if from __future__ import annotations is used at the module where the dataclass inheriting ArgumentLoader is used, it will cause field.type evaluates to string name of types like 'str', 'int' when deciding type during adding class field as an argument..
Workaround
A temporary workaround is avoiding using from __future__ import annotations when defining a class extending ArgumentLoader.
The text was updated successfully, but these errors were encountered:
Description
When retrieving type from
field.type
, type is a string literal indicating the type rather than the specific type class. Therefore, it cannot be added as type argument foradd_argument
inargparse
as it expects a Callable.Explanation
This issue arises because type evaluation is deferred when
from __future__ import annotations
is used.For example,
when import is not used
when import is used
Therefore, if
from __future__ import annotations
is used at the module where the dataclass inheriting ArgumentLoader is used, it will causefield.type
evaluates to string name of types like'str'
,'int'
when deciding type during adding class field as an argument..Workaround
A temporary workaround is avoiding using
from __future__ import annotations
when defining a class extending ArgumentLoader.The text was updated successfully, but these errors were encountered: