Skip to content

Commit f3e4197

Browse files
committed
Fix issues with * import in helpers module
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
1 parent b9eb0c3 commit f3e4197

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

examples/simple/flag.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
from dataclasses import dataclass
22

3-
from simple_parsing import ArgumentParser
3+
from simple_parsing import ArgumentParser, parse
44
from simple_parsing.helpers import flag
55

66

7-
def parse(cls, args: str = ""):
8-
"""Removes some boilerplate code from the examples."""
9-
parser = ArgumentParser() # Create an argument parser
10-
parser.add_arguments(cls, dest="hparams") # add arguments for the dataclass
11-
ns = parser.parse_args(args.split()) # parse the given `args`
12-
return ns.hparams
13-
14-
157
@dataclass
168
class HParams:
179
"""Set of options for the training of a Model."""
@@ -32,10 +24,10 @@ class HParams:
3224
"""
3325

3426
# Example 2 using the flags negative prefix
35-
assert parse(HParams, "--no-train") == HParams(train=False)
27+
assert parse(HParams, args="--no-train") == HParams(train=False)
3628

3729

38-
# showing what --help outputs
30+
# showing what --help outputs
3931
parser = ArgumentParser() # Create an argument parser
4032
parser.add_arguments(HParams, dest="hparams") # add arguments for the dataclass
4133
parser.print_help()
@@ -56,4 +48,4 @@ class HParams:
5648
(default: 0.001)
5749
--train bool, --no-train bool
5850
(default: True)
59-
"""
51+
"""

simple_parsing/helpers/__init__.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
""" Collection of helper classes and functions to reduce boilerplate code. """
2-
from .fields import *
1+
"""Collection of helper classes and functions to reduce boilerplate code."""
2+
from .fields import (
3+
field,
4+
choice,
5+
list_field,
6+
dict_field,
7+
set_field,
8+
mutable_field,
9+
subparsers,
10+
flag,
11+
flags,
12+
)
313
from .flatten import FlattenedAccess
414
from .hparams import HyperParameters
515
from .partial import Partial, config_for
@@ -13,3 +23,26 @@
1323
# For backward compatibility purposes
1424
JsonSerializable = Serializable
1525
SimpleEncoder = SimpleJsonEncoder
26+
27+
__all__ = [
28+
"FlattenedAccess",
29+
"HyperParameters",
30+
"Partial",
31+
"config_for",
32+
"FrozenSerializable",
33+
"Serializable",
34+
"SimpleJsonEncoder",
35+
"encode",
36+
"JsonSerializable",
37+
"SimpleEncoder",
38+
"YamlSerializable",
39+
"field",
40+
"choice",
41+
"list_field",
42+
"dict_field",
43+
"set_field",
44+
"mutable_field",
45+
"subparsers",
46+
"flag",
47+
"flags",
48+
]

0 commit comments

Comments
 (0)