Skip to content

Commit a4c6701

Browse files
committed
Python 3.9 support
1 parent 25644c3 commit a4c6701

File tree

4 files changed

+45
-43
lines changed

4 files changed

+45
-43
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ Tuple, Tuple[Type1, Type2, etc.], Tuple[Type, ...]
213213
Literal
214214
```
215215

216+
If you're using Python 3.9+, then you can replace `List` with `list`, `Set` with `set`, and `Tuple` with `tuple`.
217+
216218
#### `str`, `int`, and `float`
217219

218220
Each is automatically parsed to their respective types, just like argparse.
@@ -241,7 +243,7 @@ Tuples can be used to specify a fixed number of arguments with specified types u
241243

242244
#### `Literal`
243245

244-
Literal is analagous to `argparse`'s [choices](https://docs.python.org/3/library/argparse.html#choices), which specifies the values that an argument can take. For example, if arg can only be one of 'H', 1, False, or 1.0078 then you would specify that `arg: Literal['H', 1, False, 1.0078]`. For instance, `--arg False` assigns arg to False and `--arg True` throws error. The `Literal` type was introduced in Python 3.8 ([PEP 586](https://www.python.org/dev/peps/pep-0586/)) and can be imported with `from typing_extensions import Literal`.
246+
Literal is analagous to argparse's [choices](https://docs.python.org/3/library/argparse.html#choices), which specifies the values that an argument can take. For example, if arg can only be one of 'H', 1, False, or 1.0078 then you would specify that `arg: Literal['H', 1, False, 1.0078]`. For instance, `--arg False` assigns arg to False and `--arg True` throws error. The `Literal` type was introduced in Python 3.8 ([PEP 586](https://www.python.org/dev/peps/pep-0586/)) and can be imported with `from typing_extensions import Literal`.
245247

246248
#### Complex types
247249

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
package_data={'tap': ['py.typed']},
3030
install_requires=[
3131
'typing_extensions >= 3.7.4',
32-
'typing-inspect == 0.6.0'
32+
'typing-inspect >= 0.7.1'
3333
],
3434
tests_require=['pytest'],
3535
classifiers=[

tap/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__all__ = ['__version__']
22

33
# major, minor, patch
4-
version_info = 1, 6, 3
4+
version_info = 1, 7, 0
55

66
# Nice string for the version
77
__version__ = '.'.join(map(str, version_info))

tests/test_integration.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -124,46 +124,46 @@ def test_both_assigned_okay(self):
124124

125125

126126
# TODO: need to implement list[str] etc.
127-
# class ParameterizedStandardCollectionTap(Tap):
128-
# arg_list_str: list[str]
129-
# arg_list_int: list[int]
130-
# arg_list_int_default: list[int] = [1, 2, 5]
131-
# arg_set_float: set[float]
132-
# arg_set_str_default: set[str] = ['one', 'two', 'five']
133-
# arg_tuple_int: tuple[int, ...]
134-
# arg_tuple_float_default: tuple[float, float, float] = (1.0, 2.0, 5.0)
135-
# arg_tuple_str_override: tuple[str, str] = ('hi', 'there')
136-
# arg_optional_list_int: Optional[list[int]] = None
137-
138-
139-
# class ParameterizedStandardCollectionTests(TestCase):
140-
# @unittest.skipIf(sys.version_info < (3, 9), 'Parameterized standard collections (e.g., list[int]) introduced in Python 3.9')
141-
# def test_parameterized_standard_collection(self):
142-
# arg_list_str = ['a', 'b', 'pi']
143-
# arg_list_int = [-2, -5, 10]
144-
# arg_set_float = {3.54, 2.235}
145-
# arg_tuple_int = (-4, 5, 9, 103)
146-
# arg_tuple_str_override = ('why', 'so', 'many', 'tests?')
147-
# arg_optional_list_int = [5, 4, 3]
148-
149-
# args = ParameterizedStandardCollectionTap().parse_args([
150-
# '--arg_list_str', *arg_list_str,
151-
# '--arg_list_int', *[str(var) for var in arg_list_int],
152-
# '--arg_set_float', *[str(var) for var in arg_set_float],
153-
# '--arg_tuple_int', *[str(var) for var in arg_tuple_int],
154-
# '--arg_tuple_str_override', *arg_tuple_str_override,
155-
# '--arg_optional_list_int', *[str(var) for var in arg_optional_list_int]
156-
# ])
157-
158-
# self.assertEqual(args.arg_list_str, arg_list_str)
159-
# self.assertEqual(args.arg_list_int, arg_list_int)
160-
# self.assertEqual(args.arg_list_int_default, ParameterizedStandardCollectionTap.arg_list_int_default)
161-
# self.assertEqual(args.arg_set_float, arg_set_float)
162-
# self.assertEqual(args.arg_set_str_default, ParameterizedStandardCollectionTap.arg_set_str_default)
163-
# self.assertEqual(args.arg_tuple_int, arg_tuple_int)
164-
# self.assertEqual(args.arg_tuple_float_default, ParameterizedStandardCollectionTap.arg_tuple_float_default)
165-
# self.assertEqual(args.arg_tuple_str_override, arg_tuple_str_override)
166-
# self.assertEqual(args.arg_optional_list_int, arg_optional_list_int)
127+
class ParameterizedStandardCollectionTap(Tap):
128+
arg_list_str: list[str]
129+
arg_list_int: list[int]
130+
arg_list_int_default: list[int] = [1, 2, 5]
131+
arg_set_float: set[float]
132+
arg_set_str_default: set[str] = {'one', 'two', 'five'}
133+
arg_tuple_int: tuple[int, ...]
134+
arg_tuple_float_default: tuple[float, float, float] = (1.0, 2.0, 5.0)
135+
arg_tuple_str_override: tuple[str, str] = ('hi', 'there')
136+
arg_optional_list_int: Optional[list[int]] = None
137+
138+
139+
class ParameterizedStandardCollectionTests(TestCase):
140+
@unittest.skipIf(sys.version_info < (3, 9), 'Parameterized standard collections (e.g., list[int]) introduced in Python 3.9')
141+
def test_parameterized_standard_collection(self):
142+
arg_list_str = ['a', 'b', 'pi']
143+
arg_list_int = [-2, -5, 10]
144+
arg_set_float = {3.54, 2.235}
145+
arg_tuple_int = (-4, 5, 9, 103)
146+
arg_tuple_str_override = ('why', 'so')
147+
arg_optional_list_int = [5, 4, 3]
148+
149+
args = ParameterizedStandardCollectionTap().parse_args([
150+
'--arg_list_str', *arg_list_str,
151+
'--arg_list_int', *[str(var) for var in arg_list_int],
152+
'--arg_set_float', *[str(var) for var in arg_set_float],
153+
'--arg_tuple_int', *[str(var) for var in arg_tuple_int],
154+
'--arg_tuple_str_override', *arg_tuple_str_override,
155+
'--arg_optional_list_int', *[str(var) for var in arg_optional_list_int]
156+
])
157+
158+
self.assertEqual(args.arg_list_str, arg_list_str)
159+
self.assertEqual(args.arg_list_int, arg_list_int)
160+
self.assertEqual(args.arg_list_int_default, ParameterizedStandardCollectionTap.arg_list_int_default)
161+
self.assertEqual(args.arg_set_float, arg_set_float)
162+
self.assertEqual(args.arg_set_str_default, ParameterizedStandardCollectionTap.arg_set_str_default)
163+
self.assertEqual(args.arg_tuple_int, arg_tuple_int)
164+
self.assertEqual(args.arg_tuple_float_default, ParameterizedStandardCollectionTap.arg_tuple_float_default)
165+
self.assertEqual(args.arg_tuple_str_override, arg_tuple_str_override)
166+
self.assertEqual(args.arg_optional_list_int, arg_optional_list_int)
167167

168168

169169
class NestedOptionalTypesTap(Tap):

0 commit comments

Comments
 (0)