Commit 9eaea96
authored
Ruggedize cmd2's runtime type annotation validation (#1442)
* Change cmd2's runtime type annotation validation to be based on typing.get_type_hints
Previously it was based on inspect.signature. The problem is that to Python 3.10, the inspect module doesn't have a safe way of evaluating type annotations that works equivalently both in the presence or absence of "from __future__ import annotations". Hence, any attempt at using that in an app would break cmd2.
This change adds a get_types() helper function to the cmd2.utils module which uses typing.get_type_hints() to do the introspection in a safer way.
* Fix for Python 3.9 since types.NoneType doesn't exist until 3.10
* Added unit tests for new utils.get_types function
* Add a note to the CHANGELOG
* Added a new test file to cover the case representing the whole reason for this change
I first verified that this test fails on the current master branch
* Switched CHANGELOG type to Bug Fix1 parent 8d1c82c commit 9eaea96
File tree
5 files changed
+129
-47
lines changed- cmd2
- tests
5 files changed
+129
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| |||
5544 | 5545 | | |
5545 | 5546 | | |
5546 | 5547 | | |
5547 | | - | |
5548 | | - | |
5549 | | - | |
5550 | | - | |
| 5548 | + | |
| 5549 | + | |
| 5550 | + | |
| 5551 | + | |
5551 | 5552 | | |
5552 | 5553 | | |
5553 | 5554 | | |
| |||
5563 | 5564 | | |
5564 | 5565 | | |
5565 | 5566 | | |
5566 | | - | |
5567 | | - | |
5568 | | - | |
| 5567 | + | |
| 5568 | + | |
| 5569 | + | |
| 5570 | + | |
| 5571 | + | |
5569 | 5572 | | |
5570 | | - | |
| 5573 | + | |
5571 | 5574 | | |
5572 | 5575 | | |
5573 | 5576 | | |
| |||
5582 | 5585 | | |
5583 | 5586 | | |
5584 | 5587 | | |
5585 | | - | |
5586 | 5588 | | |
5587 | 5589 | | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
5588 | 5595 | | |
5589 | | - | |
5590 | | - | |
5591 | | - | |
5592 | | - | |
| 5596 | + | |
| 5597 | + | |
5593 | 5598 | | |
5594 | | - | |
| 5599 | + | |
5595 | 5600 | | |
5596 | | - | |
5597 | | - | |
5598 | | - | |
5599 | | - | |
| 5601 | + | |
| 5602 | + | |
5600 | 5603 | | |
5601 | 5604 | | |
5602 | 5605 | | |
| |||
5614 | 5617 | | |
5615 | 5618 | | |
5616 | 5619 | | |
5617 | | - | |
5618 | | - | |
5619 | | - | |
5620 | | - | |
5621 | | - | |
5622 | | - | |
| 5620 | + | |
| 5621 | + | |
| 5622 | + | |
| 5623 | + | |
| 5624 | + | |
| 5625 | + | |
| 5626 | + | |
| 5627 | + | |
| 5628 | + | |
| 5629 | + | |
5623 | 5630 | | |
5624 | 5631 | | |
5625 | 5632 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
40 | 23 | | |
41 | 24 | | |
42 | 25 | | |
| |||
1261 | 1244 | | |
1262 | 1245 | | |
1263 | 1246 | | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
0 commit comments