Skip to content

Commit f30ffbe

Browse files
committed
Now we refrain from changing underscores in postional arguments to dashes
1 parent 844c1bd commit f30ffbe

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

tap/tap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def _add_argument(self, *name_or_flags, **kwargs) -> None:
242242
kwargs['type'] = var_type
243243

244244
if self._underscores_to_dashes:
245-
name_or_flags = [name_or_flag.replace('_', '-') for name_or_flag in name_or_flags]
245+
# Replace "_" with "-" for arguments that aren't positional
246+
name_or_flags = tuple(name_or_flag.replace('_', '-') if name_or_flag.startswith('-') else name_or_flag
247+
for name_or_flag in name_or_flags)
246248

247249
super(Tap, self).add_argument(*name_or_flags, **kwargs)
248250

tests/test_integration.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,30 @@ def my_property(self):
13491349
self.assertEqual(args._get_class_dict(), result)
13501350

13511351

1352+
class TestPositionalArguments(TestCase):
1353+
1354+
def test_underscores_to_dashes_does_not_modify_positional(self):
1355+
class PositionalTap(Tap):
1356+
under_score: int
1357+
1358+
def configure(self):
1359+
self.add_argument('under_score')
1360+
1361+
args = PositionalTap(underscores_to_dashes=True).parse_args(['1'])
1362+
1363+
self.assertEqual(args.under_score, 1)
1364+
1365+
def test_positional_maintains_types(self):
1366+
class PositionalTap(Tap):
1367+
a: int
1368+
1369+
def configure(self) -> None:
1370+
self.add_argument('a')
1371+
1372+
args = PositionalTap().parse_args(['1'])
1373+
1374+
self.assertEqual(args.a, 1)
1375+
13521376
"""
13531377
- crash if default type not supported
13541378
- user specifying process_args

0 commit comments

Comments
 (0)