micropython-stubber 1.20.5__py3-none-any.whl → 1.23.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.23.0.dist-info}/LICENSE +30 -30
  2. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.23.0.dist-info}/METADATA +1 -1
  3. micropython_stubber-1.23.0.dist-info/RECORD +159 -0
  4. mpflash/README.md +184 -184
  5. mpflash/libusb_flash.ipynb +203 -203
  6. mpflash/mpflash/add_firmware.py +98 -98
  7. mpflash/mpflash/ask_input.py +236 -236
  8. mpflash/mpflash/bootloader/__init__.py +37 -36
  9. mpflash/mpflash/bootloader/manual.py +102 -102
  10. mpflash/mpflash/bootloader/micropython.py +10 -10
  11. mpflash/mpflash/bootloader/touch1200.py +45 -45
  12. mpflash/mpflash/cli_download.py +129 -129
  13. mpflash/mpflash/cli_flash.py +219 -219
  14. mpflash/mpflash/cli_group.py +98 -98
  15. mpflash/mpflash/cli_list.py +81 -81
  16. mpflash/mpflash/cli_main.py +41 -41
  17. mpflash/mpflash/common.py +164 -164
  18. mpflash/mpflash/config.py +43 -47
  19. mpflash/mpflash/connected.py +74 -74
  20. mpflash/mpflash/download.py +360 -360
  21. mpflash/mpflash/downloaded.py +130 -129
  22. mpflash/mpflash/errors.py +9 -9
  23. mpflash/mpflash/flash.py +55 -52
  24. mpflash/mpflash/flash_esp.py +59 -59
  25. mpflash/mpflash/flash_stm32.py +18 -24
  26. mpflash/mpflash/flash_stm32_cube.py +111 -111
  27. mpflash/mpflash/flash_stm32_dfu.py +104 -101
  28. mpflash/mpflash/flash_uf2.py +89 -67
  29. mpflash/mpflash/flash_uf2_boardid.py +15 -15
  30. mpflash/mpflash/flash_uf2_linux.py +129 -123
  31. mpflash/mpflash/flash_uf2_macos.py +37 -34
  32. mpflash/mpflash/flash_uf2_windows.py +38 -34
  33. mpflash/mpflash/list.py +89 -89
  34. mpflash/mpflash/logger.py +41 -41
  35. mpflash/mpflash/mpboard_id/__init__.py +93 -93
  36. mpflash/mpflash/mpboard_id/add_boards.py +255 -255
  37. mpflash/mpflash/mpboard_id/board.py +37 -37
  38. mpflash/mpflash/mpboard_id/board_id.py +86 -86
  39. mpflash/mpflash/mpboard_id/store.py +43 -43
  40. mpflash/mpflash/mpremoteboard/__init__.py +226 -221
  41. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -141
  42. mpflash/mpflash/mpremoteboard/runner.py +140 -140
  43. mpflash/mpflash/uf2disk.py +12 -12
  44. mpflash/mpflash/vendor/basicgit.py +288 -288
  45. mpflash/mpflash/vendor/click_aliases.py +91 -91
  46. mpflash/mpflash/vendor/dfu.py +165 -165
  47. mpflash/mpflash/vendor/pydfu.py +605 -605
  48. mpflash/mpflash/vendor/readme.md +2 -2
  49. mpflash/mpflash/vendor/versions.py +119 -117
  50. mpflash/mpflash/worklist.py +171 -170
  51. mpflash/poetry.lock +1588 -1588
  52. mpflash/pyproject.toml +64 -60
  53. mpflash/stm32_udev_rules.md +62 -62
  54. stubber/__init__.py +3 -3
  55. stubber/basicgit.py +294 -288
  56. stubber/board/board_info.csv +193 -193
  57. stubber/board/boot.py +34 -34
  58. stubber/board/createstubs.py +986 -986
  59. stubber/board/createstubs_db.py +825 -825
  60. stubber/board/createstubs_db_min.py +331 -331
  61. stubber/board/createstubs_db_mpy.mpy +0 -0
  62. stubber/board/createstubs_lvgl.py +741 -741
  63. stubber/board/createstubs_lvgl_min.py +741 -741
  64. stubber/board/createstubs_mem.py +766 -766
  65. stubber/board/createstubs_mem_min.py +306 -306
  66. stubber/board/createstubs_mem_mpy.mpy +0 -0
  67. stubber/board/createstubs_min.py +294 -294
  68. stubber/board/createstubs_mpy.mpy +0 -0
  69. stubber/board/fw_info.py +141 -141
  70. stubber/board/info.py +183 -183
  71. stubber/board/main.py +19 -19
  72. stubber/board/modulelist.txt +247 -247
  73. stubber/board/pyrightconfig.json +34 -34
  74. stubber/bulk/mcu_stubber.py +454 -454
  75. stubber/codemod/_partials/__init__.py +48 -48
  76. stubber/codemod/_partials/db_main.py +147 -147
  77. stubber/codemod/_partials/lvgl_main.py +77 -77
  78. stubber/codemod/_partials/modules_reader.py +80 -80
  79. stubber/codemod/add_comment.py +53 -53
  80. stubber/codemod/add_method.py +65 -65
  81. stubber/codemod/board.py +317 -317
  82. stubber/codemod/enrich.py +145 -145
  83. stubber/codemod/merge_docstub.py +284 -284
  84. stubber/codemod/modify_list.py +54 -54
  85. stubber/codemod/utils.py +57 -57
  86. stubber/commands/build_cmd.py +94 -94
  87. stubber/commands/cli.py +55 -51
  88. stubber/commands/clone_cmd.py +77 -66
  89. stubber/commands/config_cmd.py +29 -29
  90. stubber/commands/enrich_folder_cmd.py +71 -70
  91. stubber/commands/get_core_cmd.py +71 -69
  92. stubber/commands/get_docstubs_cmd.py +89 -87
  93. stubber/commands/get_frozen_cmd.py +114 -112
  94. stubber/commands/get_mcu_cmd.py +61 -56
  95. stubber/commands/merge_cmd.py +67 -66
  96. stubber/commands/publish_cmd.py +119 -119
  97. stubber/commands/stub_cmd.py +31 -30
  98. stubber/commands/switch_cmd.py +62 -54
  99. stubber/commands/variants_cmd.py +49 -48
  100. stubber/cst_transformer.py +178 -178
  101. stubber/data/board_info.csv +193 -193
  102. stubber/data/board_info.json +1729 -1729
  103. stubber/data/micropython_tags.csv +15 -15
  104. stubber/data/requirements-core-micropython.txt +38 -38
  105. stubber/data/requirements-core-pycopy.txt +39 -39
  106. stubber/downloader.py +36 -36
  107. stubber/freeze/common.py +68 -68
  108. stubber/freeze/freeze_folder.py +69 -69
  109. stubber/freeze/freeze_manifest_2.py +113 -113
  110. stubber/freeze/get_frozen.py +127 -127
  111. stubber/get_cpython.py +101 -101
  112. stubber/get_lobo.py +59 -59
  113. stubber/minify.py +418 -418
  114. stubber/publish/bump.py +86 -86
  115. stubber/publish/candidates.py +262 -262
  116. stubber/publish/database.py +18 -18
  117. stubber/publish/defaults.py +45 -45
  118. stubber/publish/enums.py +24 -24
  119. stubber/publish/helpers.py +29 -29
  120. stubber/publish/merge_docstubs.py +130 -130
  121. stubber/publish/missing_class_methods.py +49 -49
  122. stubber/publish/package.py +146 -146
  123. stubber/publish/pathnames.py +51 -51
  124. stubber/publish/publish.py +120 -120
  125. stubber/publish/pypi.py +38 -38
  126. stubber/publish/stubpackage.py +1029 -1029
  127. stubber/rst/__init__.py +9 -9
  128. stubber/rst/classsort.py +77 -77
  129. stubber/rst/lookup.py +530 -530
  130. stubber/rst/output_dict.py +401 -401
  131. stubber/rst/reader.py +822 -822
  132. stubber/rst/report_return.py +69 -69
  133. stubber/rst/rst_utils.py +540 -540
  134. stubber/stubber.py +38 -38
  135. stubber/stubs_from_docs.py +90 -90
  136. stubber/tools/manifestfile.py +655 -610
  137. stubber/tools/readme.md +7 -6
  138. stubber/update_fallback.py +117 -117
  139. stubber/update_module_list.py +123 -123
  140. stubber/utils/__init__.py +5 -5
  141. stubber/utils/config.py +127 -127
  142. stubber/utils/makeversionhdr.py +54 -54
  143. stubber/utils/manifest.py +92 -92
  144. stubber/utils/post.py +79 -79
  145. stubber/utils/repos.py +157 -154
  146. stubber/utils/stubmaker.py +139 -139
  147. stubber/utils/typed_config_toml.py +77 -77
  148. stubber/utils/versions.py +128 -120
  149. stubber/variants.py +106 -106
  150. micropython_stubber-1.20.5.dist-info/RECORD +0 -159
  151. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.23.0.dist-info}/WHEEL +0 -0
  152. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.23.0.dist-info}/entry_points.txt +0 -0
stubber/rst/lookup.py CHANGED
@@ -1,530 +1,530 @@
1
- """
2
- Lookup tables for the rst documentation stubber
3
- """
4
-
5
- from dataclasses import dataclass
6
- from typing import List, Optional, Tuple
7
-
8
- # These are shown to import
9
- __all__ = [
10
- "TYPING_IMPORT",
11
- "LOOKUP_LIST",
12
- "NONE_VERBS",
13
- "CHILD_PARENT_CLASS",
14
- "PARAM_FIXES",
15
- "MODULE_GLUE",
16
- "RST_DOC_FIXES",
17
- "DOCSTUB_SKIP",
18
- "U_MODULES",
19
- ]
20
-
21
- # all possible Types needed for the stubs - exxess types should be removed later , and otherwise won't do much harm
22
- TYPING_IMPORT: List[str] = [
23
- "from __future__ import annotations",
24
- "from typing import IO, Any, Callable, Coroutine, Dict, Generator, Iterator, List, NoReturn, Optional, Tuple, Union, NamedTuple, TypeVar",
25
- "from _typeshed import Incomplete",
26
- ]
27
-
28
-
29
- @dataclass
30
- class Fix:
31
- """A fix for a parameter or return type in the documentation that is needed to render it to a valid type annotation
32
-
33
- - from_ : the string or regex that should be fixed
34
- - to : the improved version to replace it with
35
- - module : filter the fix to be only applied to a specific module
36
- - name : filter the fix to be only applied to a specific member
37
- - is_re : the from_ string is a regular expression
38
- """
39
-
40
- from_: str
41
- "The string or regex that should be fixed"
42
- to: str
43
- "The improved version to replace it with"
44
- name: Optional[str] = None
45
- "Filter the fix to be only applied to a specific module member"
46
- module: Optional[str] = None
47
- "Filter the fix to be only applied to a specific module"
48
- is_re: bool = False
49
- "the from_ string is a regular expression"
50
-
51
-
52
- U_MODULES = [
53
- "array",
54
- "binascii",
55
- "io",
56
- "json",
57
- "os",
58
- "select",
59
- "ssl",
60
- "struct",
61
- "socket",
62
- "time",
63
- "zlib",
64
- ]
65
- """
66
- List of modules that are documented with the base name only,
67
- but can also be imported with a `u` prefix
68
- """
69
-
70
- # This table is used to try to correct the errors in the documentation,
71
- # or adapt the human readable documentation to machine readable.
72
- # it is applied to each .rst file after loading the contents.
73
- # also applies correction for some classes are documented as functions
74
-
75
- RST_DOC_FIXES: List[Tuple[str, str]] = [
76
- # remove rst highlights from docstrings
77
- (":class: attention\n", ""),
78
- # ------------------------------------------------------------------------------------------------
79
- # re.rst - function and class with the same name
80
- # done: issue https://github.com/micropython/micropython/issues/8273
81
- # TODO: Create PR fix class Match
82
- (".. method:: match.", ".. method:: Match."),
83
- (" match.end", " Match.end"),
84
- # ------------------------------------------------------------------------------------------------
85
- # collections.rst - should be fixed in v1.19
86
- # PR: https://github.com/micropython/micropython/pull/7976
87
- # keep around for older docstubs
88
- (".. function:: deque(", ".. class:: deque("),
89
- (".. function:: OrderedDict(", ".. class:: OrderedDict("),
90
- # ------------------------------------------------------------------------------------------------
91
- # generator functions - WILL_NOT_FIX in the MicroPython documentation
92
- # these are documented as functions, but return an object with the the same name as the function.
93
- # for static type analysis this is best considered as a Class, so morph them before processing.
94
- # uselect.rst
95
- (".. function:: poll(", ".. class:: poll("),
96
- # ESPNow.rst - multiple methods on a single line, split to multiline
97
- (
98
- ".. method:: AIOESPNow._aiter__() / async AIOESPNow.__anext__()",
99
- ".. method:: AIOESPNow._aiter__()\n async AIOESPNow.__anext__()",
100
- ),
101
- ]
102
-
103
-
104
- # docstubs generation, exclude stub generation for below stubs.
105
- DOCSTUB_SKIP = [
106
- "uasyncio.rst", # can create better stubs from frozen python modules.
107
- "builtins.rst", # conflicts with static type checking , has very little information anyway
108
- "re.rst", # regex is too complex
109
- ]
110
-
111
- # contains return types for functions and methods that are not clearly documented.
112
- """
113
- this is an list with manual overrides for function returns that could not efficiently be determined
114
- from their docstring description
115
- Format: a dictionary with :
116
- - key = module.[class.]function name
117
- - value : two-tuple with ( return type , priority )
118
- """
119
- LOOKUP_LIST = {
120
- "builtins.bytes": ("bytes", 0.95),
121
- "builtins.from_bytes": ("int", 0.95),
122
- "builtins.to_bytes": ("bytes", 0.95),
123
- "bytearray_at": ("bytearray", 0.95),
124
- "collections.namedtuple": ("stdlib_namedtuple", 0.95),
125
- "gc.collect": ("None", 0.95),
126
- "machine.deepsleep": ("NoReturn", 0.95),
127
- "machine.reset_cause": ("int", 0.95),
128
- "machine.reset": ("NoReturn", 0.95), # never returns
129
- "machine.Signal.value": ("int", 0.95),
130
- "machine.soft_reset": ("NoReturn", 0.95), # never returns
131
- "machine.UART.irq": ("Incomplete", 0.95), # no IRQ type defined
132
- "machine.UART.write": ("Union[int,None]", 0.95),
133
- "machine.UART.readinto": ("Union[int,None]", 0.95),
134
- "machine.UART.readline": ("Union[str,None]", 0.95),
135
- "math.isnan": ("bool", 0.95),
136
- "micropython.opt_level": ("Incomplete", 0.95), # Not clear in docstring
137
- # since 1.19 const can also be string , bytes or tuple
138
- "micropython.const": ("Const_T", 1), # const: 1 - paired with param typing
139
- "micropython.heap_lock": ("int", 1),
140
- "micropython.heap_unlock": ("int", 1),
141
- "micropython.heap_locked": ("bool", 1),
142
- "pyb.hard_reset": ("NoReturn", 0.95), # never returns
143
- "pyb.I2C.recv": ("bytes", 0.95), # complex in docstring
144
- "pyb.SPI.recv": ("bytes", 0.95), # complex in docstring
145
- "ubluetooth.BLE.irq": ("Any", 0.95), # never returns
146
- "uctypes.bytearray_at": ("bytearray", 0.95),
147
- "uctypes.bytes_at": ("bytes", 0.95),
148
- "uio.open": ("IO", 0.95), # Open a file.
149
- "uos.listdir": ("List[Incomplete]", 0.95),
150
- "os.uname": ("uname_result", 0.95),
151
- "ssl.ssl.wrap_socket": (
152
- "IO",
153
- 0.95,
154
- ), # undocumented class ssl.SSLSocket #TODO: or wrapped-socket object ?
155
- "ussl.ussl.wrap_socket": ("IO", 0.95), # undocumented class ssl.SSLSocket
156
- "usys.exit": ("NoReturn", 0.95), # never returns
157
- "utime.sleep_ms": (
158
- "Coroutine[None, None, None]", # Micropython V1.15+ ?
159
- 0.95,
160
- ),
161
- "stm.mem8": ("bytearray", 0.95), # Read/write 8 bits of memory.
162
- "stm.mem16": ("bytearray", 0.95), # Read/write 16 bits of memory.
163
- "stm.mem32": ("bytearray", 0.95), # Read/write 32 bits of memory.
164
- # Onewire documented mostly in sourcecode
165
- "_onewire.reset": ("bool", 0.95),
166
- "_onewire.scan": ("List[int]", 0.95),
167
- "_onewire.readbit": ("int", 0.95),
168
- "_onewire.readbyte": ("int", 0.95),
169
- "_onewire.writebyte": ("None", 0.95),
170
- "_onewire.writebit": ("None", 0.95),
171
- "_onewire.crc8": ("int", 0.95),
172
- # espnow
173
- "espnow.ESPNow.recv": ("Union[List, Tuple[None,None]]", 0.95), # list / ? tuple of bytestrings
174
- }
175
-
176
-
177
- # if no type has been determined, and the docstring starts with one of these verbs, then assume the return type is None
178
- # - The starting word or words with a training space
179
- NONE_VERBS = [
180
- "Activate ",
181
- "Build a ",
182
- "Cancel ",
183
- "Clear ",
184
- "Close ",
185
- "cancel ",
186
- "Configure ",
187
- "Connect ",
188
- "Deactivate ",
189
- "De-initialises ",
190
- "Deinitialises ",
191
- "Delay ",
192
- "Disable ",
193
- "Display ",
194
- "Disconnect ",
195
- "Draw ",
196
- "Enable ",
197
- "Feed the ",
198
- "Fill the ",
199
- "Generate ",
200
- "Initialise the ",
201
- "Initialize ", # US/UK spelling
202
- "Issue a ",
203
- "Load ",
204
- "Modify ",
205
- "Print ",
206
- "Register ",
207
- "Remove ",
208
- "Rename ",
209
- "Reset ",
210
- "Resets ",
211
- "Send ",
212
- "Sends ",
213
- "Set Pin ",
214
- "Set the ",
215
- "Sets",
216
- "Show ",
217
- "Stop ",
218
- "Stops ",
219
- "Sync ",
220
- "Turn ",
221
- "Wait ",
222
- "Write ",
223
- "Writes ",
224
- ]
225
-
226
- # Add additional imports to generated modules
227
- # - to allow one module te refer to another,
228
- # - to import other supporting modules
229
- # - to add missing abstract classes
230
-
231
- MODULE_GLUE = {
232
- "lcd160cr": ["from .machine import SPI"], # module returns SPI objects defined in machine
233
- "esp32": ["from __future__ import annotations"], # Class methods return Class
234
- "collections": [
235
- "from queue import Queue",
236
- "from stdlib.collections import OrderedDict as stdlib_OrderedDict, deque as stdlib_deque, namedtuple as stdlib_namedtuple",
237
- ], # dequeu is a subclass
238
- "os": [
239
- # "from stdlib.os import uname_result", # uname returns uname_result
240
- "from stdlib.os import * # type: ignore", # integrate STDLIB
241
- ],
242
- "io": ["from stdlib.io import * # type: ignore"], # integrate STDLIB
243
- "socket": ["from stdlib.socket import * # type: ignore"], # integrate STDLIB
244
- "ssl": ["from stdlib.ssl import * # type: ignore"], # integrate STDLIB
245
- # const: 3 - paired with param and return typing
246
- "micropython": ["Const_T = TypeVar('Const_T',int, float, str, bytes, Tuple) # constant"],
247
- #
248
- # "builtins": ["from stdlib.builtins import *"], # integrate STDLIB
249
- # "machine": ["from network import AbstractNIC"], # NIC is an abstract class, although not defined or used as such
250
- }
251
-
252
-
253
- PARAM_FIXES = [
254
- Fix("\\*", "*"), # change weirdly written wildcards \* --> *
255
- Fix(r"\**", "*"), # change weirdly written wildcards \* --> *
256
- Fix(r"/*", "*"), # change weirdly written wildcards \* --> *
257
- Fix(r"/)", ")"), # strange terminator in machine.USBDevice `USBDevice.active(self, [value] /)`
258
- Fix("'param'", "param"), # loose notation in documentation
259
- # illegal keywords
260
- Fix(
261
- "lambda",
262
- "lambda_fn",
263
- ),
264
- # method:: ADC.read_timed_multi((adcx, adcy, ...), (bufx, bufy, ...), timer)
265
- Fix(
266
- "(adcx, adcy, ...), (bufx, bufy, ...)",
267
- "adcs, bufs",
268
- ),
269
- # network.AbstractNIC
270
- # ifconfig([(ip, subnet, gateway, dns)])
271
- Fix(
272
- "(ip, subnet, gateway, dns)",
273
- "configtuple",
274
- ),
275
- # pyb.hid((buttons, x, y, z))
276
- Fix(
277
- "(buttons, x, y, z)",
278
- "hidtuple:Tuple",
279
- ),
280
- # esp v1.15.2 .. function:: getaddrinfo((hostname, port, lambda))
281
- Fix(
282
- "(hostname, port, lambda)",
283
- "tuple[str,int,Callable]",
284
- ),
285
- # # network
286
- # # WLANWiPy.ifconfig(if_id=0, config=['dhcp' or configtuple])
287
- # Fix(
288
- # "config=['dhcp' or configtuple]",
289
- # "config: Union[str,Tuple]='dhcp'"
290
- # ),
291
- Fix(
292
- "config='dhcp' or configtuple: Optional[Any]=None",
293
- "config: Union[str,Tuple]='dhcp'",
294
- ),
295
- # (
296
- # "='dhcp' or configtuple: Optional[Any]=None",
297
- # ": Union[str,Tuple]='dhcp'",
298
- # ),
299
- # network
300
- # CC3K.patch_program('pgm')
301
- Fix(
302
- "'pgm')",
303
- "cmd:str ,/)",
304
- ),
305
- # network
306
- Fix(
307
- "block_device or path",
308
- "block_device_or_path",
309
- ), #
310
- # network
311
- # ifconfig
312
- Fix(
313
- "(ip, subnet, gateway, dns):Optional[Any]=None",
314
- "configtuple: Optional[Tuple]",
315
- ),
316
- # framebuffer
317
- # unresolvable parameter defaults # FrameBuffer: def __init__
318
- Fix(
319
- "stride=width",
320
- "stride=-1",
321
- ),
322
- # machine.Pin.__init__ constructor - Defaults assumed from the documentation.
323
- # fixed in doc v1.18+
324
- Fix(
325
- ", value, drive, alt",
326
- ", value=None, drive=0, alt=-1",
327
- ),
328
- # machine.Pin.irq ...
329
- Fix(
330
- "trigger=(IRQ_FALLING | IRQ_RISING)",
331
- "trigger=IRQ_FALLING ",
332
- ),
333
- ## fixes for machine.py class constants
334
- # # BUG: This is not OK
335
- Fix(
336
- "pins=(SCK, MOSI, MISO)",
337
- "pins:Optional[Tuple]",
338
- ), #
339
- ## rp2.PIO.irq
340
- Fix(
341
- "trigger=IRQ_SM0|IRQ_SM1|IRQ_SM2|IRQ_SM3",
342
- "trigger=IRQ_SM0",
343
- ),
344
- # SPI.INIT - to fix error: Non-default argument follows default argument
345
- # ✅ fixed in doc v1.18+
346
- Fix(
347
- "prescaler, polarity=1",
348
- "prescaler=1, polarity=1",
349
- ),
350
- # network.LAN.init
351
- # def __init__(self, id, *, phy_type=<board_default>, phy_addr=<board_default>, phy_clock=<board_default>) -> None:
352
- Fix("=<board_default>", "=0"),
353
- # ssl
354
- # def wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None, do_handshake=True) -> Any:
355
- Fix("cert_reqs=CERT_NONE", "cert_reqs=None"),
356
- # struct.pack & pack_into
357
- # def pack(fmt, v1, v2, *args) -> bytes:
358
- Fix(", v1, v2,", ", v1,"),
359
- # esp32.RMT
360
- # # def write_pulses(self, duration, data=True) -> Any:
361
- # def write_pulses(self, duration, data:Union[bool,int]=True) -> Any:
362
- Fix(
363
- "duration, data=True",
364
- "duration, data:Union[bool,int]=True",
365
- ),
366
- # --------------------------------------------------------------------
367
- # machine
368
- # machine.PWM
369
- # # def __init__(self, dest, *, freq, duty_u16, duty_ns) -> None: ...
370
- # def __init__(self, dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0) -> None: ...
371
- Fix(
372
- "dest, *, freq, duty_u16, duty_ns, invert",
373
- "dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0, invert=False",
374
- ),
375
- # most specific fix first
376
- Fix(
377
- "dest, *, freq, duty_u16, duty_ns",
378
- "dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0",
379
- ),
380
- # machine.ADC
381
- # # def __init__(self, id, *, sample_ns, atten) -> None: ...
382
- # def __init__(self, id, *, sample_ns:Optional[int]=0, atten:Optional[int]=ATTN_0DB) -> None: ...
383
- Fix(
384
- "id, *, sample_ns, atten",
385
- "id, *, sample_ns:Optional[int]=0, atten:Optional[int]=ATTN_0DB",
386
- ),
387
- # machine.I2C
388
- # # def __init__(self, id, *, scl, sda, freq=400000) -> None: ...
389
- # def __init__(self, id=-1, *, scl:Optional[Pin]=None, sda:Optional[Pin]=None, freq=400000) -> None: ...
390
- Fix(
391
- "id, *, scl, sda, freq=400000",
392
- "id:Union[int,str]=-1, *, scl:Optional[Union[Pin,str]]=None, sda:Optional[Union[Pin,str]]=None, freq=400_000",
393
- ),
394
- # network.WLAN
395
- # def config(self, param) -> Any:
396
- # def config(self, *args, **kwargs) -> Any:
397
- Fix(
398
- "param",
399
- "*args, **kwargs",
400
- name="WLAN.config",
401
- ),
402
- # machine.UART
403
- # def __init__(self, id, ...) -> None: ...
404
- # def __init__(self, id, *args, **kwargs) -> None: ...
405
- Fix(
406
- "id, ...",
407
- "id, *args, **kwargs",
408
- name="UART.__init__",
409
- ),
410
- # machine.SPI
411
- # # def __init__(self, id, *args) -> None: ...
412
- # def __init__(self, id, *args, **kwargs) -> None: ...
413
- Fix("id, ...", "id, *args, **kwargs", name="SPI.__init__"),
414
- # machine.Signal
415
- # def __init__(self, pin_obj, invert=False) -> None: ...
416
- # def __init__(self, pin_obj, *args, invert=False) -> None: ...
417
- Fix("pin_obj, invert", "pin_obj, *args, invert", name="Signal.__init__"),
418
- # machine.Timer
419
- # def __init__(self, id, /, *args) -> None: ...
420
- # def init(self,id, *, mode=PERIODIC, period=-1, callback=None) -> None: ...
421
- Fix("id, /, ...", "id=-1, *args, **kwargs", name="Timer.__init__"),
422
- # --------------------------------------------------------------------
423
- # pyb
424
- # def freq(sysclk, hclk, pclk1, pclk2) -> Tuple:
425
- # def freq(sysclk=0, hclk=0, pclk1=0, pclk2=0) -> Tuple:
426
- Fix("sysclk, hclk, pclk1, pclk2", "sysclk=0, hclk=0, pclk1=0, pclk2=0"),
427
- # Timer.__init__
428
- # def __init__(self, id, *args) -> None: ...
429
- # def __init__(self, id, *, freq=..., prescaler=..., period=..., mode=UP, div=1, callback=None, deadtime=0) -> None:
430
- Fix(
431
- "id, *args",
432
- "id, *, freq=-1, prescaler=-1, period=-1, mode=UP, div=1, callback=None, deadtime=0",
433
- name="Timer.__init__",
434
- ),
435
- # Timer.channel
436
- # def channel(self, channel, mode, *args) -> Any:
437
- # def channel(self, channel, mode, pin=None, *args) -> Any:
438
- Fix("channel, mode, ...", "channel, mode, pin=None, *args"),
439
- # pyb SPI
440
- # def __init__(self, bus, *args) -> None: ...
441
- # def __init__(self,bus, mode, baudrate=328125, *, prescaler=-1, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None) -> None:
442
- Fix(
443
- "bus, ...",
444
- "bus, mode, baudrate=328125, *, prescaler=-1, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None",
445
- ),
446
- # PYB CAN.setfiler
447
- # def setfilter(self, bank, mode, fifo, params, *, rtr, extframe=False) -> None:
448
- # def setfilter(self, bank, mode, fifo, params, *, rtr=..., extframe=False) -> None:
449
- Fix(
450
- "bank, mode, fifo, params, *, rtr, extframe=False",
451
- "bank, mode, fifo, params, *, rtr=None, extframe=False",
452
- ),
453
- # DOC: DocUpdate ? deal with overloads for Flash and Partition .readblock/writeblocks
454
- Fix(
455
- r"\s*block_num, buf, offset\s*\)",
456
- "block_num, buf, offset: Optional[int] = 0)",
457
- is_re=True,
458
- ),
459
- # # This is a cleanup something that went wrong before
460
- # Fix("**kwargs: Optional[Any]","**kwargs")
461
- # os.mount - optional parameters
462
- # fsobj, mount_point, *, readonly)
463
- Fix(
464
- "fsobj, mount_point, *, readonly)",
465
- "fsobj, mount_point, *, readonly=False)",
466
- ),
467
- # micropython.const
468
- Fix("expr)", "expr:Const_T)", name="const"), # const: 3 - paired with return typing,
469
- # ------ ESPNow.rst uses (ESP32 only) after the class / function prototype
470
- Fix(r"\(ESP\d+\s+only\)", "", is_re=True), # ESP32 / ESP8266 Only
471
- # espnow.ESPNow.send is missing several params
472
- Fix(
473
- "msg)",
474
- "peer, msg,mac=None,sync=True)",
475
- name="ESPNow.send",
476
- ),
477
- Fix(
478
- "msg)",
479
- "peer, msg,mac=None,sync=True)",
480
- name="ESPNow.asend",
481
- ),
482
- ]
483
-
484
- # List of classes and their parent classes that should be added to the class definition
485
- CHILD_PARENT_CLASS = {
486
- # machine
487
- # SoftSPI is defined before SPI, so baseclass is not yet available - but in a .pyi that is OK
488
- "SoftSPI": "SPI",
489
- "SoftI2C": "I2C",
490
- "Switch": "Pin",
491
- "Signal": "Pin",
492
- # uio # unclear regarding deprecation in python 3.12
493
- # "IOBase": "IO", # DOCME not in documentation
494
- "TextIOWrapper": "IO", # "TextIOBase, TextIO", # based on Stdlib
495
- "FileIO": "IO", # "RawIOBase, BinaryIO", # based on Stdlib
496
- "StringIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
497
- "BytesIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
498
- "BufferedWriter": "IOBase", # DOCME: not in documentation # "BufferedWriter": "BufferedIOBase", # based on Stdlib
499
- # uzlib
500
- # "DecompIO": "IO", # https://docs.python.org/3/library/typing.html#other-concrete-types
501
- # -------------------------------------------------------------------------------------
502
- # network - AbstractNIC is definined in docstub network.pyi , but not actually used
503
- # "WLAN": "AbstractNIC",
504
- # "WLANWiPy": "AbstractNIC",
505
- # "CC3K": "AbstractNIC",
506
- # "WIZNET5K": "AbstractNIC",
507
- # -------------------------------------------------------------------------------------
508
- # uhashlib
509
- # "md5": "hash", # BUG: hash is not defined in the MCU stubs
510
- # "sha1": "hash",
511
- # "sha256": "hash",
512
- # collections
513
- "OrderedDict": "stdlib_OrderedDict",
514
- "namedtuple": "tuple",
515
- "deque": "stdlib_deque",
516
- # ESPNow
517
- "ESPNow": "ESPNowBase,Iterator", # causes issue with mypy
518
- "AIOESPNow": "ESPNow",
519
- # array
520
- "array": "List",
521
- }
522
-
523
-
524
- # TODO : implement the execution of this list during merge
525
- # - this is a list of functions, classes methods and constantsn that are not detected at runtime, but are avaialble and documented
526
- # the standard merge only adds documentation to detected functions.
527
- FORCE_NON_DETECED = [
528
- ("btree", "Btree", ["esp32", "esp8266"]), # Is not detected runtime
529
- ("espnow", "ESPNow.peers_table", ["esp32"]), # Is not detected runtime
530
- ]
1
+ """
2
+ Lookup tables for the rst documentation stubber
3
+ """
4
+
5
+ from dataclasses import dataclass
6
+ from typing import List, Optional, Tuple
7
+
8
+ # These are shown to import
9
+ __all__ = [
10
+ "TYPING_IMPORT",
11
+ "LOOKUP_LIST",
12
+ "NONE_VERBS",
13
+ "CHILD_PARENT_CLASS",
14
+ "PARAM_FIXES",
15
+ "MODULE_GLUE",
16
+ "RST_DOC_FIXES",
17
+ "DOCSTUB_SKIP",
18
+ "U_MODULES",
19
+ ]
20
+
21
+ # all possible Types needed for the stubs - exxess types should be removed later , and otherwise won't do much harm
22
+ TYPING_IMPORT: List[str] = [
23
+ "from __future__ import annotations",
24
+ "from typing import IO, Any, Callable, Coroutine, Dict, Generator, Iterator, List, NoReturn, Optional, Tuple, Union, NamedTuple, TypeVar",
25
+ "from _typeshed import Incomplete",
26
+ ]
27
+
28
+
29
+ @dataclass
30
+ class Fix:
31
+ """A fix for a parameter or return type in the documentation that is needed to render it to a valid type annotation
32
+
33
+ - from_ : the string or regex that should be fixed
34
+ - to : the improved version to replace it with
35
+ - module : filter the fix to be only applied to a specific module
36
+ - name : filter the fix to be only applied to a specific member
37
+ - is_re : the from_ string is a regular expression
38
+ """
39
+
40
+ from_: str
41
+ "The string or regex that should be fixed"
42
+ to: str
43
+ "The improved version to replace it with"
44
+ name: Optional[str] = None
45
+ "Filter the fix to be only applied to a specific module member"
46
+ module: Optional[str] = None
47
+ "Filter the fix to be only applied to a specific module"
48
+ is_re: bool = False
49
+ "the from_ string is a regular expression"
50
+
51
+
52
+ U_MODULES = [
53
+ "array",
54
+ "binascii",
55
+ "io",
56
+ "json",
57
+ "os",
58
+ "select",
59
+ "ssl",
60
+ "struct",
61
+ "socket",
62
+ "time",
63
+ "zlib",
64
+ ]
65
+ """
66
+ List of modules that are documented with the base name only,
67
+ but can also be imported with a `u` prefix
68
+ """
69
+
70
+ # This table is used to try to correct the errors in the documentation,
71
+ # or adapt the human readable documentation to machine readable.
72
+ # it is applied to each .rst file after loading the contents.
73
+ # also applies correction for some classes are documented as functions
74
+
75
+ RST_DOC_FIXES: List[Tuple[str, str]] = [
76
+ # remove rst highlights from docstrings
77
+ (":class: attention\n", ""),
78
+ # ------------------------------------------------------------------------------------------------
79
+ # re.rst - function and class with the same name
80
+ # done: issue https://github.com/micropython/micropython/issues/8273
81
+ # TODO: Create PR fix class Match
82
+ (".. method:: match.", ".. method:: Match."),
83
+ (" match.end", " Match.end"),
84
+ # ------------------------------------------------------------------------------------------------
85
+ # collections.rst - should be fixed in v1.19
86
+ # PR: https://github.com/micropython/micropython/pull/7976
87
+ # keep around for older docstubs
88
+ (".. function:: deque(", ".. class:: deque("),
89
+ (".. function:: OrderedDict(", ".. class:: OrderedDict("),
90
+ # ------------------------------------------------------------------------------------------------
91
+ # generator functions - WILL_NOT_FIX in the MicroPython documentation
92
+ # these are documented as functions, but return an object with the the same name as the function.
93
+ # for static type analysis this is best considered as a Class, so morph them before processing.
94
+ # uselect.rst
95
+ (".. function:: poll(", ".. class:: poll("),
96
+ # ESPNow.rst - multiple methods on a single line, split to multiline
97
+ (
98
+ ".. method:: AIOESPNow._aiter__() / async AIOESPNow.__anext__()",
99
+ ".. method:: AIOESPNow._aiter__()\n async AIOESPNow.__anext__()",
100
+ ),
101
+ ]
102
+
103
+
104
+ # docstubs generation, exclude stub generation for below stubs.
105
+ DOCSTUB_SKIP = [
106
+ "uasyncio.rst", # can create better stubs from frozen python modules.
107
+ "builtins.rst", # conflicts with static type checking , has very little information anyway
108
+ "re.rst", # regex is too complex
109
+ ]
110
+
111
+ # contains return types for functions and methods that are not clearly documented.
112
+ """
113
+ this is an list with manual overrides for function returns that could not efficiently be determined
114
+ from their docstring description
115
+ Format: a dictionary with :
116
+ - key = module.[class.]function name
117
+ - value : two-tuple with ( return type , priority )
118
+ """
119
+ LOOKUP_LIST = {
120
+ "builtins.bytes": ("bytes", 0.95),
121
+ "builtins.from_bytes": ("int", 0.95),
122
+ "builtins.to_bytes": ("bytes", 0.95),
123
+ "bytearray_at": ("bytearray", 0.95),
124
+ "collections.namedtuple": ("stdlib_namedtuple", 0.95),
125
+ "gc.collect": ("None", 0.95),
126
+ "machine.deepsleep": ("NoReturn", 0.95),
127
+ "machine.reset_cause": ("int", 0.95),
128
+ "machine.reset": ("NoReturn", 0.95), # never returns
129
+ "machine.Signal.value": ("int", 0.95),
130
+ "machine.soft_reset": ("NoReturn", 0.95), # never returns
131
+ "machine.UART.irq": ("Incomplete", 0.95), # no IRQ type defined
132
+ "machine.UART.write": ("Union[int,None]", 0.95),
133
+ "machine.UART.readinto": ("Union[int,None]", 0.95),
134
+ "machine.UART.readline": ("Union[str,None]", 0.95),
135
+ "math.isnan": ("bool", 0.95),
136
+ "micropython.opt_level": ("Incomplete", 0.95), # Not clear in docstring
137
+ # since 1.19 const can also be string , bytes or tuple
138
+ "micropython.const": ("Const_T", 1), # const: 1 - paired with param typing
139
+ "micropython.heap_lock": ("int", 1),
140
+ "micropython.heap_unlock": ("int", 1),
141
+ "micropython.heap_locked": ("bool", 1),
142
+ "pyb.hard_reset": ("NoReturn", 0.95), # never returns
143
+ "pyb.I2C.recv": ("bytes", 0.95), # complex in docstring
144
+ "pyb.SPI.recv": ("bytes", 0.95), # complex in docstring
145
+ "ubluetooth.BLE.irq": ("Any", 0.95), # never returns
146
+ "uctypes.bytearray_at": ("bytearray", 0.95),
147
+ "uctypes.bytes_at": ("bytes", 0.95),
148
+ "uio.open": ("IO", 0.95), # Open a file.
149
+ "uos.listdir": ("List[Incomplete]", 0.95),
150
+ "os.uname": ("uname_result", 0.95),
151
+ "ssl.ssl.wrap_socket": (
152
+ "IO",
153
+ 0.95,
154
+ ), # undocumented class ssl.SSLSocket #TODO: or wrapped-socket object ?
155
+ "ussl.ussl.wrap_socket": ("IO", 0.95), # undocumented class ssl.SSLSocket
156
+ "usys.exit": ("NoReturn", 0.95), # never returns
157
+ "utime.sleep_ms": (
158
+ "Coroutine[None, None, None]", # Micropython V1.15+ ?
159
+ 0.95,
160
+ ),
161
+ "stm.mem8": ("bytearray", 0.95), # Read/write 8 bits of memory.
162
+ "stm.mem16": ("bytearray", 0.95), # Read/write 16 bits of memory.
163
+ "stm.mem32": ("bytearray", 0.95), # Read/write 32 bits of memory.
164
+ # Onewire documented mostly in sourcecode
165
+ "_onewire.reset": ("bool", 0.95),
166
+ "_onewire.scan": ("List[int]", 0.95),
167
+ "_onewire.readbit": ("int", 0.95),
168
+ "_onewire.readbyte": ("int", 0.95),
169
+ "_onewire.writebyte": ("None", 0.95),
170
+ "_onewire.writebit": ("None", 0.95),
171
+ "_onewire.crc8": ("int", 0.95),
172
+ # espnow
173
+ "espnow.ESPNow.recv": ("Union[List, Tuple[None,None]]", 0.95), # list / ? tuple of bytestrings
174
+ }
175
+
176
+
177
+ # if no type has been determined, and the docstring starts with one of these verbs, then assume the return type is None
178
+ # - The starting word or words with a training space
179
+ NONE_VERBS = [
180
+ "Activate ",
181
+ "Build a ",
182
+ "Cancel ",
183
+ "Clear ",
184
+ "Close ",
185
+ "cancel ",
186
+ "Configure ",
187
+ "Connect ",
188
+ "Deactivate ",
189
+ "De-initialises ",
190
+ "Deinitialises ",
191
+ "Delay ",
192
+ "Disable ",
193
+ "Display ",
194
+ "Disconnect ",
195
+ "Draw ",
196
+ "Enable ",
197
+ "Feed the ",
198
+ "Fill the ",
199
+ "Generate ",
200
+ "Initialise the ",
201
+ "Initialize ", # US/UK spelling
202
+ "Issue a ",
203
+ "Load ",
204
+ "Modify ",
205
+ "Print ",
206
+ "Register ",
207
+ "Remove ",
208
+ "Rename ",
209
+ "Reset ",
210
+ "Resets ",
211
+ "Send ",
212
+ "Sends ",
213
+ "Set Pin ",
214
+ "Set the ",
215
+ "Sets",
216
+ "Show ",
217
+ "Stop ",
218
+ "Stops ",
219
+ "Sync ",
220
+ "Turn ",
221
+ "Wait ",
222
+ "Write ",
223
+ "Writes ",
224
+ ]
225
+
226
+ # Add additional imports to generated modules
227
+ # - to allow one module te refer to another,
228
+ # - to import other supporting modules
229
+ # - to add missing abstract classes
230
+
231
+ MODULE_GLUE = {
232
+ "lcd160cr": ["from .machine import SPI"], # module returns SPI objects defined in machine
233
+ "esp32": ["from __future__ import annotations"], # Class methods return Class
234
+ "collections": [
235
+ "from queue import Queue",
236
+ "from stdlib.collections import OrderedDict as stdlib_OrderedDict, deque as stdlib_deque, namedtuple as stdlib_namedtuple",
237
+ ], # dequeu is a subclass
238
+ "os": [
239
+ # "from stdlib.os import uname_result", # uname returns uname_result
240
+ "from stdlib.os import * # type: ignore", # integrate STDLIB
241
+ ],
242
+ "io": ["from stdlib.io import * # type: ignore"], # integrate STDLIB
243
+ "socket": ["from stdlib.socket import * # type: ignore"], # integrate STDLIB
244
+ "ssl": ["from stdlib.ssl import * # type: ignore"], # integrate STDLIB
245
+ # const: 3 - paired with param and return typing
246
+ "micropython": ["Const_T = TypeVar('Const_T',int, float, str, bytes, Tuple) # constant"],
247
+ #
248
+ # "builtins": ["from stdlib.builtins import *"], # integrate STDLIB
249
+ # "machine": ["from network import AbstractNIC"], # NIC is an abstract class, although not defined or used as such
250
+ }
251
+
252
+
253
+ PARAM_FIXES = [
254
+ Fix("\\*", "*"), # change weirdly written wildcards \* --> *
255
+ Fix(r"\**", "*"), # change weirdly written wildcards \* --> *
256
+ Fix(r"/*", "*"), # change weirdly written wildcards \* --> *
257
+ Fix(r"/)", ")"), # strange terminator in machine.USBDevice `USBDevice.active(self, [value] /)`
258
+ Fix("'param'", "param"), # loose notation in documentation
259
+ # illegal keywords
260
+ Fix(
261
+ "lambda",
262
+ "lambda_fn",
263
+ ),
264
+ # method:: ADC.read_timed_multi((adcx, adcy, ...), (bufx, bufy, ...), timer)
265
+ Fix(
266
+ "(adcx, adcy, ...), (bufx, bufy, ...)",
267
+ "adcs, bufs",
268
+ ),
269
+ # network.AbstractNIC
270
+ # ifconfig([(ip, subnet, gateway, dns)])
271
+ Fix(
272
+ "(ip, subnet, gateway, dns)",
273
+ "configtuple",
274
+ ),
275
+ # pyb.hid((buttons, x, y, z))
276
+ Fix(
277
+ "(buttons, x, y, z)",
278
+ "hidtuple:Tuple",
279
+ ),
280
+ # esp v1.15.2 .. function:: getaddrinfo((hostname, port, lambda))
281
+ Fix(
282
+ "(hostname, port, lambda)",
283
+ "tuple[str,int,Callable]",
284
+ ),
285
+ # # network
286
+ # # WLANWiPy.ifconfig(if_id=0, config=['dhcp' or configtuple])
287
+ # Fix(
288
+ # "config=['dhcp' or configtuple]",
289
+ # "config: Union[str,Tuple]='dhcp'"
290
+ # ),
291
+ Fix(
292
+ "config='dhcp' or configtuple: Optional[Any]=None",
293
+ "config: Union[str,Tuple]='dhcp'",
294
+ ),
295
+ # (
296
+ # "='dhcp' or configtuple: Optional[Any]=None",
297
+ # ": Union[str,Tuple]='dhcp'",
298
+ # ),
299
+ # network
300
+ # CC3K.patch_program('pgm')
301
+ Fix(
302
+ "'pgm')",
303
+ "cmd:str ,/)",
304
+ ),
305
+ # network
306
+ Fix(
307
+ "block_device or path",
308
+ "block_device_or_path",
309
+ ), #
310
+ # network
311
+ # ifconfig
312
+ Fix(
313
+ "(ip, subnet, gateway, dns):Optional[Any]=None",
314
+ "configtuple: Optional[Tuple]",
315
+ ),
316
+ # framebuffer
317
+ # unresolvable parameter defaults # FrameBuffer: def __init__
318
+ Fix(
319
+ "stride=width",
320
+ "stride=-1",
321
+ ),
322
+ # machine.Pin.__init__ constructor - Defaults assumed from the documentation.
323
+ # fixed in doc v1.18+
324
+ Fix(
325
+ ", value, drive, alt",
326
+ ", value=None, drive=0, alt=-1",
327
+ ),
328
+ # machine.Pin.irq ...
329
+ Fix(
330
+ "trigger=(IRQ_FALLING | IRQ_RISING)",
331
+ "trigger=IRQ_FALLING ",
332
+ ),
333
+ ## fixes for machine.py class constants
334
+ # # BUG: This is not OK
335
+ Fix(
336
+ "pins=(SCK, MOSI, MISO)",
337
+ "pins:Optional[Tuple]",
338
+ ), #
339
+ ## rp2.PIO.irq
340
+ Fix(
341
+ "trigger=IRQ_SM0|IRQ_SM1|IRQ_SM2|IRQ_SM3",
342
+ "trigger=IRQ_SM0",
343
+ ),
344
+ # SPI.INIT - to fix error: Non-default argument follows default argument
345
+ # ✅ fixed in doc v1.18+
346
+ Fix(
347
+ "prescaler, polarity=1",
348
+ "prescaler=1, polarity=1",
349
+ ),
350
+ # network.LAN.init
351
+ # def __init__(self, id, *, phy_type=<board_default>, phy_addr=<board_default>, phy_clock=<board_default>) -> None:
352
+ Fix("=<board_default>", "=0"),
353
+ # ssl
354
+ # def wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None, do_handshake=True) -> Any:
355
+ Fix("cert_reqs=CERT_NONE", "cert_reqs=None"),
356
+ # struct.pack & pack_into
357
+ # def pack(fmt, v1, v2, *args) -> bytes:
358
+ Fix(", v1, v2,", ", v1,"),
359
+ # esp32.RMT
360
+ # # def write_pulses(self, duration, data=True) -> Any:
361
+ # def write_pulses(self, duration, data:Union[bool,int]=True) -> Any:
362
+ Fix(
363
+ "duration, data=True",
364
+ "duration, data:Union[bool,int]=True",
365
+ ),
366
+ # --------------------------------------------------------------------
367
+ # machine
368
+ # machine.PWM
369
+ # # def __init__(self, dest, *, freq, duty_u16, duty_ns) -> None: ...
370
+ # def __init__(self, dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0) -> None: ...
371
+ Fix(
372
+ "dest, *, freq, duty_u16, duty_ns, invert",
373
+ "dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0, invert=False",
374
+ ),
375
+ # most specific fix first
376
+ Fix(
377
+ "dest, *, freq, duty_u16, duty_ns",
378
+ "dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0",
379
+ ),
380
+ # machine.ADC
381
+ # # def __init__(self, id, *, sample_ns, atten) -> None: ...
382
+ # def __init__(self, id, *, sample_ns:Optional[int]=0, atten:Optional[int]=ATTN_0DB) -> None: ...
383
+ Fix(
384
+ "id, *, sample_ns, atten",
385
+ "id, *, sample_ns:Optional[int]=0, atten:Optional[int]=ATTN_0DB",
386
+ ),
387
+ # machine.I2C
388
+ # # def __init__(self, id, *, scl, sda, freq=400000) -> None: ...
389
+ # def __init__(self, id=-1, *, scl:Optional[Pin]=None, sda:Optional[Pin]=None, freq=400000) -> None: ...
390
+ Fix(
391
+ "id, *, scl, sda, freq=400000",
392
+ "id:Union[int,str]=-1, *, scl:Optional[Union[Pin,str]]=None, sda:Optional[Union[Pin,str]]=None, freq=400_000",
393
+ ),
394
+ # network.WLAN
395
+ # def config(self, param) -> Any:
396
+ # def config(self, *args, **kwargs) -> Any:
397
+ Fix(
398
+ "param",
399
+ "*args, **kwargs",
400
+ name="WLAN.config",
401
+ ),
402
+ # machine.UART
403
+ # def __init__(self, id, ...) -> None: ...
404
+ # def __init__(self, id, *args, **kwargs) -> None: ...
405
+ Fix(
406
+ "id, ...",
407
+ "id, *args, **kwargs",
408
+ name="UART.__init__",
409
+ ),
410
+ # machine.SPI
411
+ # # def __init__(self, id, *args) -> None: ...
412
+ # def __init__(self, id, *args, **kwargs) -> None: ...
413
+ Fix("id, ...", "id, *args, **kwargs", name="SPI.__init__"),
414
+ # machine.Signal
415
+ # def __init__(self, pin_obj, invert=False) -> None: ...
416
+ # def __init__(self, pin_obj, *args, invert=False) -> None: ...
417
+ Fix("pin_obj, invert", "pin_obj, *args, invert", name="Signal.__init__"),
418
+ # machine.Timer
419
+ # def __init__(self, id, /, *args) -> None: ...
420
+ # def init(self,id, *, mode=PERIODIC, period=-1, callback=None) -> None: ...
421
+ Fix("id, /, ...", "id=-1, *args, **kwargs", name="Timer.__init__"),
422
+ # --------------------------------------------------------------------
423
+ # pyb
424
+ # def freq(sysclk, hclk, pclk1, pclk2) -> Tuple:
425
+ # def freq(sysclk=0, hclk=0, pclk1=0, pclk2=0) -> Tuple:
426
+ Fix("sysclk, hclk, pclk1, pclk2", "sysclk=0, hclk=0, pclk1=0, pclk2=0"),
427
+ # Timer.__init__
428
+ # def __init__(self, id, *args) -> None: ...
429
+ # def __init__(self, id, *, freq=..., prescaler=..., period=..., mode=UP, div=1, callback=None, deadtime=0) -> None:
430
+ Fix(
431
+ "id, *args",
432
+ "id, *, freq=-1, prescaler=-1, period=-1, mode=UP, div=1, callback=None, deadtime=0",
433
+ name="Timer.__init__",
434
+ ),
435
+ # Timer.channel
436
+ # def channel(self, channel, mode, *args) -> Any:
437
+ # def channel(self, channel, mode, pin=None, *args) -> Any:
438
+ Fix("channel, mode, ...", "channel, mode, pin=None, *args"),
439
+ # pyb SPI
440
+ # def __init__(self, bus, *args) -> None: ...
441
+ # def __init__(self,bus, mode, baudrate=328125, *, prescaler=-1, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None) -> None:
442
+ Fix(
443
+ "bus, ...",
444
+ "bus, mode, baudrate=328125, *, prescaler=-1, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None",
445
+ ),
446
+ # PYB CAN.setfiler
447
+ # def setfilter(self, bank, mode, fifo, params, *, rtr, extframe=False) -> None:
448
+ # def setfilter(self, bank, mode, fifo, params, *, rtr=..., extframe=False) -> None:
449
+ Fix(
450
+ "bank, mode, fifo, params, *, rtr, extframe=False",
451
+ "bank, mode, fifo, params, *, rtr=None, extframe=False",
452
+ ),
453
+ # DOC: DocUpdate ? deal with overloads for Flash and Partition .readblock/writeblocks
454
+ Fix(
455
+ r"\s*block_num, buf, offset\s*\)",
456
+ "block_num, buf, offset: Optional[int] = 0)",
457
+ is_re=True,
458
+ ),
459
+ # # This is a cleanup something that went wrong before
460
+ # Fix("**kwargs: Optional[Any]","**kwargs")
461
+ # os.mount - optional parameters
462
+ # fsobj, mount_point, *, readonly)
463
+ Fix(
464
+ "fsobj, mount_point, *, readonly)",
465
+ "fsobj, mount_point, *, readonly=False)",
466
+ ),
467
+ # micropython.const
468
+ Fix("expr)", "expr:Const_T)", name="const"), # const: 3 - paired with return typing,
469
+ # ------ ESPNow.rst uses (ESP32 only) after the class / function prototype
470
+ Fix(r"\(ESP\d+\s+only\)", "", is_re=True), # ESP32 / ESP8266 Only
471
+ # espnow.ESPNow.send is missing several params
472
+ Fix(
473
+ "msg)",
474
+ "peer, msg,mac=None,sync=True)",
475
+ name="ESPNow.send",
476
+ ),
477
+ Fix(
478
+ "msg)",
479
+ "peer, msg,mac=None,sync=True)",
480
+ name="ESPNow.asend",
481
+ ),
482
+ ]
483
+
484
+ # List of classes and their parent classes that should be added to the class definition
485
+ CHILD_PARENT_CLASS = {
486
+ # machine
487
+ # SoftSPI is defined before SPI, so baseclass is not yet available - but in a .pyi that is OK
488
+ "SoftSPI": "SPI",
489
+ "SoftI2C": "I2C",
490
+ "Switch": "Pin",
491
+ "Signal": "Pin",
492
+ # uio # unclear regarding deprecation in python 3.12
493
+ # "IOBase": "IO", # DOCME not in documentation
494
+ "TextIOWrapper": "IO", # "TextIOBase, TextIO", # based on Stdlib
495
+ "FileIO": "IO", # "RawIOBase, BinaryIO", # based on Stdlib
496
+ "StringIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
497
+ "BytesIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
498
+ "BufferedWriter": "IOBase", # DOCME: not in documentation # "BufferedWriter": "BufferedIOBase", # based on Stdlib
499
+ # uzlib
500
+ # "DecompIO": "IO", # https://docs.python.org/3/library/typing.html#other-concrete-types
501
+ # -------------------------------------------------------------------------------------
502
+ # network - AbstractNIC is definined in docstub network.pyi , but not actually used
503
+ # "WLAN": "AbstractNIC",
504
+ # "WLANWiPy": "AbstractNIC",
505
+ # "CC3K": "AbstractNIC",
506
+ # "WIZNET5K": "AbstractNIC",
507
+ # -------------------------------------------------------------------------------------
508
+ # uhashlib
509
+ # "md5": "hash", # BUG: hash is not defined in the MCU stubs
510
+ # "sha1": "hash",
511
+ # "sha256": "hash",
512
+ # collections
513
+ "OrderedDict": "stdlib_OrderedDict",
514
+ "namedtuple": "tuple",
515
+ "deque": "stdlib_deque",
516
+ # ESPNow
517
+ "ESPNow": "ESPNowBase,Iterator", # causes issue with mypy
518
+ "AIOESPNow": "ESPNow",
519
+ # array
520
+ "array": "List",
521
+ }
522
+
523
+
524
+ # TODO : implement the execution of this list during merge
525
+ # - this is a list of functions, classes methods and constantsn that are not detected at runtime, but are avaialble and documented
526
+ # the standard merge only adds documentation to detected functions.
527
+ FORCE_NON_DETECED = [
528
+ ("btree", "Btree", ["esp32", "esp8266"]), # Is not detected runtime
529
+ ("espnow", "ESPNow.peers_table", ["esp32"]), # Is not detected runtime
530
+ ]