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