|
22 | 22 |
|
23 | 23 | import logging |
24 | 24 | import textwrap |
| 25 | +from num2words import num2words as num |
25 | 26 | from typing import List |
26 | 27 | import warnings |
27 | 28 |
|
|
51 | 52 | '``"``': "``", |
52 | 53 | } |
53 | 54 |
|
54 | | -word_digit = [ |
55 | | - "zero", |
56 | | - "one", |
57 | | - "two", |
58 | | - "three", |
59 | | - "four", |
60 | | - "five", |
61 | | - "six", |
62 | | - "seven", |
63 | | - "eight", |
64 | | - "nine", |
65 | | -] |
66 | | - |
67 | 55 | superlatif = ["st", "nd", "rd", "th"] |
68 | 56 |
|
69 | | -superlatif_digit = [ |
70 | | - "", |
71 | | - "first", |
72 | | - "second", |
73 | | - "third", |
74 | | - "fourth", |
75 | | - "fifth", |
76 | | - "sixth", |
77 | | - "seventh", |
78 | | - "eighth", |
79 | | - "ninth", |
80 | | -] |
81 | | - |
82 | 57 |
|
83 | 58 | CLEANUP = { |
84 | 59 | ",, ": ", ", |
@@ -167,9 +142,10 @@ def to_py_arg_name(name: str) -> str: |
167 | 142 | if arg[1].isdigit(): |
168 | 143 | raise ValueError(f"The code needs to be expanded to handle numbers") |
169 | 144 | elif arg[1:3] not in superlatif: |
170 | | - arg = f"{word_digit[int(arg[0])]}{arg[1:]}" |
| 145 | + arg = f"{num(arg[0])}{arg[1:]}" |
171 | 146 | else: |
172 | | - arg = f"{superlatif_digit[int(arg[0])]}{arg[3:]}" |
| 147 | + arg = f"{num(arg[0], to="ordinal")}{arg[3:]}" |
| 148 | + print(arg) |
173 | 149 |
|
174 | 150 | if ("," in arg and "--" in arg) or arg == "–": |
175 | 151 | return "" |
@@ -2189,6 +2165,11 @@ def __init__( |
2189 | 2165 | self._description = description |
2190 | 2166 | self._initial_argument = initial_argument |
2191 | 2167 |
|
| 2168 | + @property |
| 2169 | + def py_arg_name(self) -> str: |
| 2170 | + """Python-compatible term.""" |
| 2171 | + return to_py_arg_name(self._name) |
| 2172 | + |
2192 | 2173 | @property |
2193 | 2174 | def is_arg_elipsis(self): |
2194 | 2175 | """ |
@@ -2343,11 +2324,6 @@ def str_types(self, join_str: str) -> str: |
2343 | 2324 | ptype_str = join_str.join([parm_type.__name__ for parm_type in self.types]) |
2344 | 2325 | return ptype_str |
2345 | 2326 |
|
2346 | | - @property |
2347 | | - def py_arg_name(self) -> str: |
2348 | | - """Python-compatible term.""" |
2349 | | - return to_py_arg_name(self._name) |
2350 | | - |
2351 | 2327 | def resized_description( |
2352 | 2328 | self, description: str | None = None, max_length: int = 100, indent: str = "" |
2353 | 2329 | ) -> List[str]: |
@@ -2877,8 +2853,14 @@ def py_source(self, custom_functions=None, indent=""): |
2877 | 2853 | """ |
2878 | 2854 | if custom_functions is None or self.py_name not in custom_functions.py_names: |
2879 | 2855 |
|
2880 | | - if len(self.py_args) > 0: |
2881 | | - command = 'command = f"' + self.name + ",{" + "},{".join(self.py_args) + '}"\n' |
| 2856 | + if len(self.arg_desc) > 0: |
| 2857 | + command = 'command = f"' + self.name |
| 2858 | + for arg in self.arg_desc: |
| 2859 | + command += ',{' |
| 2860 | + command += arg.py_arg_name |
| 2861 | + command += '}' |
| 2862 | + command += '"\n' |
| 2863 | + # ",{" + "},{".join(self.arg_desc.py_arg_name) + '}"\n' |
2882 | 2864 | else: |
2883 | 2865 | command = 'command = f"' + self.name + '"\n' |
2884 | 2866 | return_command = "return self.run(command, **kwargs)\n" |
|
0 commit comments