micropython-stubber 1.23.1.post1__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 (152) hide show
  1. {micropython_stubber-1.23.1.post1.dist-info → micropython_stubber-1.23.2.dist-info}/LICENSE +30 -30
  2. {micropython_stubber-1.23.1.post1.dist-info → micropython_stubber-1.23.2.dist-info}/METADATA +4 -4
  3. micropython_stubber-1.23.2.dist-info/RECORD +158 -0
  4. mpflash/README.md +220 -220
  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/basicgit.py +284 -284
  9. mpflash/mpflash/bootloader/__init__.py +2 -2
  10. mpflash/mpflash/bootloader/activate.py +60 -60
  11. mpflash/mpflash/bootloader/detect.py +82 -82
  12. mpflash/mpflash/bootloader/manual.py +101 -101
  13. mpflash/mpflash/bootloader/micropython.py +12 -12
  14. mpflash/mpflash/bootloader/touch1200.py +36 -36
  15. mpflash/mpflash/cli_download.py +129 -129
  16. mpflash/mpflash/cli_flash.py +224 -216
  17. mpflash/mpflash/cli_group.py +111 -111
  18. mpflash/mpflash/cli_list.py +87 -87
  19. mpflash/mpflash/cli_main.py +39 -39
  20. mpflash/mpflash/common.py +210 -166
  21. mpflash/mpflash/config.py +44 -44
  22. mpflash/mpflash/connected.py +96 -77
  23. mpflash/mpflash/download.py +364 -364
  24. mpflash/mpflash/downloaded.py +130 -130
  25. mpflash/mpflash/errors.py +9 -9
  26. mpflash/mpflash/flash/__init__.py +55 -55
  27. mpflash/mpflash/flash/esp.py +59 -59
  28. mpflash/mpflash/flash/stm32.py +19 -19
  29. mpflash/mpflash/flash/stm32_dfu.py +104 -104
  30. mpflash/mpflash/flash/uf2/__init__.py +88 -88
  31. mpflash/mpflash/flash/uf2/boardid.py +15 -15
  32. mpflash/mpflash/flash/uf2/linux.py +136 -130
  33. mpflash/mpflash/flash/uf2/macos.py +42 -42
  34. mpflash/mpflash/flash/uf2/uf2disk.py +12 -12
  35. mpflash/mpflash/flash/uf2/windows.py +43 -43
  36. mpflash/mpflash/flash/worklist.py +170 -170
  37. mpflash/mpflash/list.py +106 -106
  38. mpflash/mpflash/logger.py +41 -41
  39. mpflash/mpflash/mpboard_id/__init__.py +93 -93
  40. mpflash/mpflash/mpboard_id/add_boards.py +251 -251
  41. mpflash/mpflash/mpboard_id/board.py +37 -37
  42. mpflash/mpflash/mpboard_id/board_id.py +86 -86
  43. mpflash/mpflash/mpboard_id/store.py +43 -43
  44. mpflash/mpflash/mpremoteboard/__init__.py +266 -266
  45. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -141
  46. mpflash/mpflash/mpremoteboard/runner.py +140 -140
  47. mpflash/mpflash/vendor/click_aliases.py +91 -91
  48. mpflash/mpflash/vendor/dfu.py +165 -165
  49. mpflash/mpflash/vendor/pydfu.py +605 -605
  50. mpflash/mpflash/vendor/readme.md +2 -2
  51. mpflash/mpflash/versions.py +135 -135
  52. mpflash/poetry.lock +1599 -1599
  53. mpflash/pyproject.toml +65 -65
  54. mpflash/stm32_udev_rules.md +62 -62
  55. stubber/__init__.py +3 -3
  56. stubber/board/board_info.csv +193 -193
  57. stubber/board/boot.py +34 -34
  58. stubber/board/createstubs.py +1004 -986
  59. stubber/board/createstubs_db.py +826 -825
  60. stubber/board/createstubs_db_min.py +332 -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 +767 -766
  65. stubber/board/createstubs_mem_min.py +307 -306
  66. stubber/board/createstubs_mem_mpy.mpy +0 -0
  67. stubber/board/createstubs_min.py +295 -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 +437 -437
  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 +151 -145
  83. stubber/codemod/merge_docstub.py +284 -284
  84. stubber/codemod/modify_list.py +54 -54
  85. stubber/codemod/utils.py +56 -56
  86. stubber/commands/build_cmd.py +94 -94
  87. stubber/commands/cli.py +49 -49
  88. stubber/commands/clone_cmd.py +78 -78
  89. stubber/commands/config_cmd.py +29 -29
  90. stubber/commands/enrich_folder_cmd.py +71 -71
  91. stubber/commands/get_core_cmd.py +71 -71
  92. stubber/commands/get_docstubs_cmd.py +92 -92
  93. stubber/commands/get_frozen_cmd.py +117 -117
  94. stubber/commands/get_mcu_cmd.py +102 -102
  95. stubber/commands/merge_cmd.py +66 -66
  96. stubber/commands/publish_cmd.py +118 -118
  97. stubber/commands/stub_cmd.py +31 -31
  98. stubber/commands/switch_cmd.py +62 -62
  99. stubber/commands/variants_cmd.py +48 -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 +37 -37
  107. stubber/freeze/common.py +72 -72
  108. stubber/freeze/freeze_folder.py +69 -69
  109. stubber/freeze/freeze_manifest_2.py +126 -126
  110. stubber/freeze/get_frozen.py +131 -131
  111. stubber/get_cpython.py +112 -112
  112. stubber/get_lobo.py +59 -59
  113. stubber/minify.py +423 -423
  114. stubber/publish/bump.py +86 -86
  115. stubber/publish/candidates.py +275 -275
  116. stubber/publish/database.py +18 -18
  117. stubber/publish/defaults.py +40 -40
  118. stubber/publish/enums.py +24 -24
  119. stubber/publish/helpers.py +29 -29
  120. stubber/publish/merge_docstubs.py +136 -132
  121. stubber/publish/missing_class_methods.py +51 -51
  122. stubber/publish/package.py +150 -150
  123. stubber/publish/pathnames.py +51 -51
  124. stubber/publish/publish.py +120 -120
  125. stubber/publish/pypi.py +42 -42
  126. stubber/publish/stubpackage.py +1055 -1051
  127. stubber/rst/__init__.py +9 -9
  128. stubber/rst/classsort.py +78 -78
  129. stubber/rst/lookup.py +533 -531
  130. stubber/rst/output_dict.py +401 -401
  131. stubber/rst/reader.py +814 -814
  132. stubber/rst/report_return.py +77 -77
  133. stubber/rst/rst_utils.py +541 -541
  134. stubber/stubber.py +38 -38
  135. stubber/stubs_from_docs.py +90 -90
  136. stubber/tools/manifestfile.py +654 -654
  137. stubber/tools/readme.md +6 -6
  138. stubber/update_fallback.py +117 -117
  139. stubber/update_module_list.py +123 -123
  140. stubber/utils/__init__.py +6 -6
  141. stubber/utils/config.py +137 -137
  142. stubber/utils/makeversionhdr.py +54 -54
  143. stubber/utils/manifest.py +90 -90
  144. stubber/utils/post.py +80 -80
  145. stubber/utils/repos.py +156 -156
  146. stubber/utils/stubmaker.py +139 -139
  147. stubber/utils/typed_config_toml.py +80 -80
  148. stubber/variants.py +106 -106
  149. micropython_stubber-1.23.1.post1.dist-info/RECORD +0 -159
  150. mpflash/basicgit.py +0 -288
  151. {micropython_stubber-1.23.1.post1.dist-info → micropython_stubber-1.23.2.dist-info}/WHEEL +0 -0
  152. {micropython_stubber-1.23.1.post1.dist-info → micropython_stubber-1.23.2.dist-info}/entry_points.txt +0 -0
stubber/rst/lookup.py CHANGED
@@ -1,531 +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
- "espnow": ["from _espnow import ESPNowBase"], # ESPNowBase is an undocumented base class
251
- }
252
-
253
-
254
- PARAM_FIXES = [
255
- Fix("\\*", "*"), # change weirdly written wildcards \* --> *
256
- Fix(r"\**", "*"), # change weirdly written wildcards \* --> *
257
- Fix(r"/*", "*"), # change weirdly written wildcards \* --> *
258
- Fix(r"/)", ")"), # strange terminator in machine.USBDevice `USBDevice.active(self, [value] /)`
259
- Fix("'param'", "param"), # loose notation in documentation
260
- # illegal keywords
261
- Fix(
262
- "lambda",
263
- "lambda_fn",
264
- ),
265
- # method:: ADC.read_timed_multi((adcx, adcy, ...), (bufx, bufy, ...), timer)
266
- Fix(
267
- "(adcx, adcy, ...), (bufx, bufy, ...)",
268
- "adcs, bufs",
269
- ),
270
- # network.AbstractNIC
271
- # ifconfig([(ip, subnet, gateway, dns)])
272
- Fix(
273
- "(ip, subnet, gateway, dns)",
274
- "configtuple",
275
- ),
276
- # pyb.hid((buttons, x, y, z))
277
- Fix(
278
- "(buttons, x, y, z)",
279
- "hidtuple:Tuple",
280
- ),
281
- # esp v1.15.2 .. function:: getaddrinfo((hostname, port, lambda))
282
- Fix(
283
- "(hostname, port, lambda)",
284
- "tuple[str,int,Callable]",
285
- ),
286
- # # network
287
- # # WLANWiPy.ifconfig(if_id=0, config=['dhcp' or configtuple])
288
- # Fix(
289
- # "config=['dhcp' or configtuple]",
290
- # "config: Union[str,Tuple]='dhcp'"
291
- # ),
292
- Fix(
293
- "config='dhcp' or configtuple: Optional[Any]=None",
294
- "config: Union[str,Tuple]='dhcp'",
295
- ),
296
- # (
297
- # "='dhcp' or configtuple: Optional[Any]=None",
298
- # ": Union[str,Tuple]='dhcp'",
299
- # ),
300
- # network
301
- # CC3K.patch_program('pgm')
302
- Fix(
303
- "'pgm')",
304
- "cmd:str ,/)",
305
- ),
306
- # network
307
- Fix(
308
- "block_device or path",
309
- "block_device_or_path",
310
- ), #
311
- # network
312
- # ifconfig
313
- Fix(
314
- "(ip, subnet, gateway, dns):Optional[Any]=None",
315
- "configtuple: Optional[Tuple]",
316
- ),
317
- # framebuffer
318
- # unresolvable parameter defaults # FrameBuffer: def __init__
319
- Fix(
320
- "stride=width",
321
- "stride=-1",
322
- ),
323
- # machine.Pin.__init__ constructor - Defaults assumed from the documentation.
324
- # fixed in doc v1.18+
325
- Fix(
326
- ", value, drive, alt",
327
- ", value=None, drive=0, alt=-1",
328
- ),
329
- # machine.Pin.irq ...
330
- Fix(
331
- "trigger=(IRQ_FALLING | IRQ_RISING)",
332
- "trigger=IRQ_FALLING ",
333
- ),
334
- ## fixes for machine.py class constants
335
- # # BUG: This is not OK
336
- Fix(
337
- "pins=(SCK, MOSI, MISO)",
338
- "pins:Optional[Tuple]",
339
- ), #
340
- ## rp2.PIO.irq
341
- Fix(
342
- "trigger=IRQ_SM0|IRQ_SM1|IRQ_SM2|IRQ_SM3",
343
- "trigger=IRQ_SM0",
344
- ),
345
- # SPI.INIT - to fix error: Non-default argument follows default argument
346
- # ✅ fixed in doc v1.18+
347
- Fix(
348
- "prescaler, polarity=1",
349
- "prescaler=1, polarity=1",
350
- ),
351
- # network.LAN.init
352
- # def __init__(self, id, *, phy_type=<board_default>, phy_addr=<board_default>, phy_clock=<board_default>) -> None:
353
- Fix("=<board_default>", "=0"),
354
- # ssl
355
- # def wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None, do_handshake=True) -> Any:
356
- Fix("cert_reqs=CERT_NONE", "cert_reqs=None"),
357
- # struct.pack & pack_into
358
- # def pack(fmt, v1, v2, *args) -> bytes:
359
- Fix(", v1, v2,", ", v1,"),
360
- # esp32.RMT
361
- # # def write_pulses(self, duration, data=True) -> Any:
362
- # def write_pulses(self, duration, data:Union[bool,int]=True) -> Any:
363
- Fix(
364
- "duration, data=True",
365
- "duration, data:Union[bool,int]=True",
366
- ),
367
- # --------------------------------------------------------------------
368
- # machine
369
- # machine.PWM
370
- # # def __init__(self, dest, *, freq, duty_u16, duty_ns) -> None: ...
371
- # def __init__(self, dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0) -> None: ...
372
- Fix(
373
- "dest, *, freq, duty_u16, duty_ns, invert",
374
- "dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0, invert=False",
375
- ),
376
- # most specific fix first
377
- Fix(
378
- "dest, *, freq, duty_u16, duty_ns",
379
- "dest, *, freq=0,duty=0, duty_u16=0, duty_ns=0",
380
- ),
381
- # machine.ADC
382
- # # def __init__(self, id, *, sample_ns, atten) -> None: ...
383
- # def __init__(self, id, *, sample_ns:Optional[int]=0, atten:Optional[int]=ATTN_0DB) -> None: ...
384
- Fix(
385
- "id, *, sample_ns, atten",
386
- "id, *, sample_ns:Optional[int]=0, atten:Optional[int]=ATTN_0DB",
387
- ),
388
- # machine.I2C
389
- # # def __init__(self, id, *, scl, sda, freq=400000) -> None: ...
390
- # def __init__(self, id=-1, *, scl:Optional[Pin]=None, sda:Optional[Pin]=None, freq=400000) -> None: ...
391
- Fix(
392
- "id, *, scl, sda, freq=400000",
393
- "id:Union[int,str]=-1, *, scl:Optional[Union[Pin,str]]=None, sda:Optional[Union[Pin,str]]=None, freq=400_000",
394
- ),
395
- # network.WLAN
396
- # def config(self, param) -> Any:
397
- # def config(self, *args, **kwargs) -> Any:
398
- Fix(
399
- "param",
400
- "*args, **kwargs",
401
- name="WLAN.config",
402
- ),
403
- # machine.UART
404
- # def __init__(self, id, ...) -> None: ...
405
- # def __init__(self, id, *args, **kwargs) -> None: ...
406
- Fix(
407
- "id, ...",
408
- "id, *args, **kwargs",
409
- name="UART.__init__",
410
- ),
411
- # machine.SPI
412
- # # def __init__(self, id, *args) -> None: ...
413
- # def __init__(self, id, *args, **kwargs) -> None: ...
414
- Fix("id, ...", "id, *args, **kwargs", name="SPI.__init__"),
415
- # machine.Signal
416
- # def __init__(self, pin_obj, invert=False) -> None: ...
417
- # def __init__(self, pin_obj, *args, invert=False) -> None: ...
418
- Fix("pin_obj, invert", "pin_obj, *args, invert", name="Signal.__init__"),
419
- # machine.Timer
420
- # def __init__(self, id, /, *args) -> None: ...
421
- # def init(self,id, *, mode=PERIODIC, period=-1, callback=None) -> None: ...
422
- Fix("id, /, ...", "id=-1, *args, **kwargs", name="Timer.__init__"),
423
- # --------------------------------------------------------------------
424
- # pyb
425
- # def freq(sysclk, hclk, pclk1, pclk2) -> Tuple:
426
- # def freq(sysclk=0, hclk=0, pclk1=0, pclk2=0) -> Tuple:
427
- Fix("sysclk, hclk, pclk1, pclk2", "sysclk=0, hclk=0, pclk1=0, pclk2=0"),
428
- # Timer.__init__
429
- # def __init__(self, id, *args) -> None: ...
430
- # def __init__(self, id, *, freq=..., prescaler=..., period=..., mode=UP, div=1, callback=None, deadtime=0) -> None:
431
- Fix(
432
- "id, *args",
433
- "id, *, freq=-1, prescaler=-1, period=-1, mode=UP, div=1, callback=None, deadtime=0",
434
- name="Timer.__init__",
435
- ),
436
- # Timer.channel
437
- # def channel(self, channel, mode, *args) -> Any:
438
- # def channel(self, channel, mode, pin=None, *args) -> Any:
439
- Fix("channel, mode, ...", "channel, mode, pin=None, *args"),
440
- # pyb SPI
441
- # def __init__(self, bus, *args) -> None: ...
442
- # def __init__(self,bus, mode, baudrate=328125, *, prescaler=-1, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None) -> None:
443
- Fix(
444
- "bus, ...",
445
- "bus, mode, baudrate=328125, *, prescaler=-1, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None",
446
- ),
447
- # PYB CAN.setfiler
448
- # def setfilter(self, bank, mode, fifo, params, *, rtr, extframe=False) -> None:
449
- # def setfilter(self, bank, mode, fifo, params, *, rtr=..., extframe=False) -> None:
450
- Fix(
451
- "bank, mode, fifo, params, *, rtr, extframe=False",
452
- "bank, mode, fifo, params, *, rtr=None, extframe=False",
453
- ),
454
- # DOC: DocUpdate ? deal with overloads for Flash and Partition .readblock/writeblocks
455
- Fix(
456
- r"\s*block_num, buf, offset\s*\)",
457
- "block_num, buf, offset: Optional[int] = 0)",
458
- is_re=True,
459
- ),
460
- # # This is a cleanup something that went wrong before
461
- # Fix("**kwargs: Optional[Any]","**kwargs")
462
- # os.mount - optional parameters
463
- # fsobj, mount_point, *, readonly)
464
- Fix(
465
- "fsobj, mount_point, *, readonly)",
466
- "fsobj, mount_point, *, readonly=False)",
467
- ),
468
- # micropython.const
469
- Fix("expr)", "expr:Const_T)", name="const"), # const: 3 - paired with return typing,
470
- # ------ ESPNow.rst uses (ESP32 only) after the class / function prototype
471
- Fix(r"\(ESP\d+\s+only\)", "", is_re=True), # ESP32 / ESP8266 Only
472
- # espnow.ESPNow.send is missing several params
473
- Fix(
474
- "msg)",
475
- "peer, msg,mac=None,sync=True)",
476
- name="ESPNow.send",
477
- ),
478
- Fix(
479
- "msg)",
480
- "peer, msg,mac=None,sync=True)",
481
- name="ESPNow.asend",
482
- ),
483
- ]
484
-
485
- # List of classes and their parent classes that should be added to the class definition
486
- CHILD_PARENT_CLASS = {
487
- # machine
488
- # SoftSPI is defined before SPI, so baseclass is not yet available - but in a .pyi that is OK
489
- "SoftSPI": "SPI",
490
- "SoftI2C": "I2C",
491
- "Switch": "Pin",
492
- "Signal": "Pin",
493
- # uio # unclear regarding deprecation in python 3.12
494
- # "IOBase": "IO", # DOCME not in documentation
495
- "TextIOWrapper": "IO", # "TextIOBase, TextIO", # based on Stdlib
496
- "FileIO": "IO", # "RawIOBase, BinaryIO", # based on Stdlib
497
- "StringIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
498
- "BytesIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
499
- "BufferedWriter": "IOBase", # DOCME: not in documentation # "BufferedWriter": "BufferedIOBase", # based on Stdlib
500
- # uzlib
501
- # "DecompIO": "IO", # https://docs.python.org/3/library/typing.html#other-concrete-types
502
- # -------------------------------------------------------------------------------------
503
- # network - AbstractNIC is definined in docstub network.pyi , but not actually used
504
- # "WLAN": "AbstractNIC",
505
- # "WLANWiPy": "AbstractNIC",
506
- # "CC3K": "AbstractNIC",
507
- # "WIZNET5K": "AbstractNIC",
508
- # -------------------------------------------------------------------------------------
509
- # uhashlib
510
- # "md5": "hash", # BUG: hash is not defined in the MCU stubs
511
- # "sha1": "hash",
512
- # "sha256": "hash",
513
- # collections
514
- "OrderedDict": "stdlib_OrderedDict",
515
- "namedtuple": "tuple",
516
- "deque": "stdlib_deque",
517
- # ESPNow
518
- "ESPNow": "ESPNowBase,Iterator", # causes issue with mypy
519
- "AIOESPNow": "ESPNow",
520
- # array
521
- "array": "List",
522
- }
523
-
524
-
525
- # TODO : implement the execution of this list during merge
526
- # - this is a list of functions, classes methods and constantsn that are not detected at runtime, but are avaialble and documented
527
- # the standard merge only adds documentation to detected functions.
528
- FORCE_NON_DETECED = [
529
- ("btree", "Btree", ["esp32", "esp8266"]), # Is not detected runtime
530
- ("espnow", "ESPNow.peers_table", ["esp32"]), # Is not detected runtime
531
- ]
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
+ ]