micropython-stubber 1.24.1__py3-none-any.whl → 1.24.4__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 (90) hide show
  1. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/METADATA +9 -29
  2. micropython_stubber-1.24.4.dist-info/RECORD +107 -0
  3. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/WHEEL +1 -1
  4. stubber/__init__.py +1 -1
  5. stubber/board/createstubs.py +44 -38
  6. stubber/board/createstubs_db.py +17 -12
  7. stubber/board/createstubs_db_min.py +63 -63
  8. stubber/board/createstubs_db_mpy.mpy +0 -0
  9. stubber/board/createstubs_mem.py +17 -12
  10. stubber/board/createstubs_mem_min.py +99 -99
  11. stubber/board/createstubs_mem_mpy.mpy +0 -0
  12. stubber/board/createstubs_min.py +111 -112
  13. stubber/board/createstubs_mpy.mpy +0 -0
  14. stubber/board/modulelist.txt +27 -27
  15. stubber/codemod/board.py +1 -1
  16. stubber/codemod/enrich.py +13 -13
  17. stubber/codemod/merge_docstub.py +83 -53
  18. stubber/codemod/visitors/type_helpers.py +143 -41
  19. stubber/commands/enrich_folder_cmd.py +17 -17
  20. stubber/commands/get_docstubs_cmd.py +27 -9
  21. stubber/commands/get_frozen_cmd.py +1 -0
  22. stubber/commands/merge_cmd.py +2 -4
  23. stubber/merge_config.py +5 -36
  24. stubber/minify.py +3 -3
  25. stubber/modcat.py +118 -0
  26. stubber/publish/merge_docstubs.py +22 -5
  27. stubber/publish/stubpackage.py +33 -28
  28. stubber/rst/lookup.py +6 -23
  29. stubber/rst/reader.py +8 -13
  30. stubber/stubs_from_docs.py +2 -1
  31. stubber/tools/manifestfile.py +2 -1
  32. stubber/{cst_transformer.py → typing_collector.py} +36 -4
  33. micropython_stubber-1.24.1.dist-info/RECORD +0 -161
  34. mpflash/README.md +0 -220
  35. mpflash/libusb_flash.ipynb +0 -203
  36. mpflash/mpflash/__init__.py +0 -0
  37. mpflash/mpflash/add_firmware.py +0 -98
  38. mpflash/mpflash/ask_input.py +0 -236
  39. mpflash/mpflash/basicgit.py +0 -324
  40. mpflash/mpflash/bootloader/__init__.py +0 -2
  41. mpflash/mpflash/bootloader/activate.py +0 -60
  42. mpflash/mpflash/bootloader/detect.py +0 -82
  43. mpflash/mpflash/bootloader/manual.py +0 -101
  44. mpflash/mpflash/bootloader/micropython.py +0 -12
  45. mpflash/mpflash/bootloader/touch1200.py +0 -36
  46. mpflash/mpflash/cli_download.py +0 -129
  47. mpflash/mpflash/cli_flash.py +0 -224
  48. mpflash/mpflash/cli_group.py +0 -111
  49. mpflash/mpflash/cli_list.py +0 -87
  50. mpflash/mpflash/cli_main.py +0 -39
  51. mpflash/mpflash/common.py +0 -217
  52. mpflash/mpflash/config.py +0 -44
  53. mpflash/mpflash/connected.py +0 -96
  54. mpflash/mpflash/download.py +0 -364
  55. mpflash/mpflash/downloaded.py +0 -138
  56. mpflash/mpflash/errors.py +0 -9
  57. mpflash/mpflash/flash/__init__.py +0 -55
  58. mpflash/mpflash/flash/esp.py +0 -59
  59. mpflash/mpflash/flash/stm32.py +0 -19
  60. mpflash/mpflash/flash/stm32_dfu.py +0 -104
  61. mpflash/mpflash/flash/uf2/__init__.py +0 -88
  62. mpflash/mpflash/flash/uf2/boardid.py +0 -15
  63. mpflash/mpflash/flash/uf2/linux.py +0 -136
  64. mpflash/mpflash/flash/uf2/macos.py +0 -42
  65. mpflash/mpflash/flash/uf2/uf2disk.py +0 -12
  66. mpflash/mpflash/flash/uf2/windows.py +0 -43
  67. mpflash/mpflash/flash/worklist.py +0 -170
  68. mpflash/mpflash/list.py +0 -106
  69. mpflash/mpflash/logger.py +0 -41
  70. mpflash/mpflash/mpboard_id/__init__.py +0 -98
  71. mpflash/mpflash/mpboard_id/add_boards.py +0 -262
  72. mpflash/mpflash/mpboard_id/board.py +0 -37
  73. mpflash/mpflash/mpboard_id/board_id.py +0 -90
  74. mpflash/mpflash/mpboard_id/board_info.zip +0 -0
  75. mpflash/mpflash/mpboard_id/store.py +0 -48
  76. mpflash/mpflash/mpremoteboard/__init__.py +0 -271
  77. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +0 -152
  78. mpflash/mpflash/mpremoteboard/runner.py +0 -140
  79. mpflash/mpflash/vendor/board_database.py +0 -185
  80. mpflash/mpflash/vendor/click_aliases.py +0 -91
  81. mpflash/mpflash/vendor/dfu.py +0 -165
  82. mpflash/mpflash/vendor/pydfu.py +0 -605
  83. mpflash/mpflash/vendor/readme.md +0 -12
  84. mpflash/mpflash/versions.py +0 -123
  85. mpflash/poetry.lock +0 -2603
  86. mpflash/pyproject.toml +0 -66
  87. mpflash/stm32_udev_rules.md +0 -63
  88. stubber/codemod/test_enrich.py +0 -87
  89. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/LICENSE +0 -0
  90. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/entry_points.txt +0 -0
@@ -38,8 +38,8 @@ L='port'
38
38
  K='.'
39
39
  I=AttributeError
40
40
  H=False
41
- G='/'
42
- E=None
41
+ G=None
42
+ E='/'
43
43
  D=OSError
44
44
  C='version'
45
45
  B=''
@@ -53,8 +53,9 @@ try:from collections import OrderedDict as l
53
53
  except O:from ucollections import OrderedDict as l
54
54
  __version__='v1.24.0'
55
55
  A3=2
56
- A4=2
57
- A5=['lib','/lib','/sd/lib','/flash/lib',K]
56
+ A4=44
57
+ A5=2
58
+ A6=['lib','/lib','/sd/lib','/flash/lib',K]
58
59
  class J:
59
60
  DEBUG=10;INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=P
60
61
  @staticmethod
@@ -72,7 +73,7 @@ class J:
72
73
  A=J.getLogger(t)
73
74
  J.basicConfig(level=J.INFO)
74
75
  class Stubber:
75
- def __init__(B,path=E,firmware_id=E):
76
+ def __init__(B,path=B,firmware_id=B):
76
77
  C=firmware_id
77
78
  try:
78
79
  if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
@@ -83,12 +84,12 @@ class Stubber:
83
84
  else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
84
85
  B._start_free=F.mem_free()
85
86
  if path:
86
- if path.endswith(G):path=path[:-1]
87
+ if path.endswith(E):path=path[:-1]
87
88
  else:path=get_root()
88
- B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
89
- try:X(path+G)
89
+ B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',E)
90
+ try:X(path+E)
90
91
  except D:A.error('error creating stub folder {}'.format(path))
91
- B.problematic=['upip','upysh','webrepl_setup','http_client','http_client_ssl','http_server','http_server_ssl'];B.excluded=['webrepl','_webrepl','port_diag','example_sub_led.py','example_pub_button.py'];B.modules=[];B._json_name=E;B._json_first=H
92
+ B.problematic=['upip','upysh','webrepl_setup','http_client','http_client_ssl','http_server','http_server_ssl'];B.excluded=['webrepl','_webrepl','port_diag','example_sub_led.py','example_pub_button.py'];B.modules=[];B._json_name=G;B._json_first=H
92
93
  def get_obj_attributes(L,item_instance):
93
94
  H=item_instance;C=[];K=[]
94
95
  for A in N(H):
@@ -114,39 +115,39 @@ class Stubber:
114
115
  B=module_name
115
116
  if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
116
117
  if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
117
- I='{}/{}.pyi'.format(C.path,B.replace(K,G));F.collect();E=H
118
- try:E=C.create_module_stub(B,I)
118
+ I='{}/{}.pyi'.format(C.path,B.replace(K,E));F.collect();G=H
119
+ try:G=C.create_module_stub(B,I)
119
120
  except D:return H
120
- F.collect();return E
121
- def create_module_stub(J,module_name,file_name=E):
121
+ F.collect();return G
122
+ def create_module_stub(J,module_name,file_name=G):
122
123
  I=file_name;C=module_name
123
- if I is E:L=C.replace(K,'_')+'.pyi';I=J.path+G+L
124
- else:L=I.split(G)[-1]
125
- if G in C:C=C.replace(G,K)
126
- N=E
127
- try:N=__import__(C,E,E,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,L,Q))
124
+ if I is G:L=C.replace(K,'_')+'.pyi';I=J.path+E+L
125
+ else:L=I.split(E)[-1]
126
+ if E in C:C=C.replace(E,K)
127
+ N=G
128
+ try:N=__import__(C,G,G,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,L,Q))
128
129
  except O:return H
129
130
  X(I)
130
- with M(I,h)as P:R=c(J.info).replace('OrderedDict(',B).replace('})','}');S='"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(C,J._fwid,R,__version__);P.write(S);P.write('from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n');J.write_object_stub(P,N,C,B)
131
+ with M(I,h)as P:R=c(J.info).replace('OrderedDict(',B).replace('})','}');S='"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(C,J._fwid,R,__version__);P.write(S);P.write('from __future__ import annotations\nfrom typing import Any, Final, Generator\nfrom _typeshed import Incomplete\n\n');J.write_object_stub(P,N,C,B)
131
132
  J.report_add(C,I)
132
133
  if C not in{'os','sys','logging','gc'}:
133
134
  try:del N
134
135
  except(D,r):A.warning('could not del new_module')
135
136
  F.collect();return T
136
137
  def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
137
- Z=' at ...>';Y='generator';X='{0}{1}: {3} = {2}\n';W='bound_method';V='Incomplete';O=in_class;N='Exception';M=object_expr;K=' at ';J=fp;E=indent;F.collect()
138
+ Y=' at ...>';X='{0}{1}: {3} = {2}\n';W='bound_method';V='Incomplete';O=in_class;N='Exception';M=object_expr;K=' at ';J=fp;E=indent;F.collect()
138
139
  if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
139
- a,P=L.get_obj_attributes(M)
140
+ Z,P=L.get_obj_attributes(M)
140
141
  if P:A.error(P)
141
- for(C,H,I,b,d)in a:
142
+ for(C,H,I,a,c)in Z:
142
143
  if C in['classmethod','staticmethod','BaseException',N]:continue
143
144
  if C[0].isdigit():A.warning('NameError: invalid name {}'.format(C));continue
144
- if I=="<class 'type'>"and R(E)<=A4*4:
145
+ if I=="<class 'type'>"and R(E)<=A5*4:
145
146
  Q=B;S=C.endswith(N)or C.endswith('Error')or C in['KeyboardInterrupt','StopIteration','SystemExit']
146
147
  if S:Q=N
147
148
  D='\n{}class {}({}):\n'.format(E,C,Q)
148
149
  if S:D+=E+' ...\n';J.write(D);continue
149
- J.write(D);L.write_object_stub(J,b,'{0}.{1}'.format(obj_name,C),E+' ',O+1);D=E+' def __init__(self, *argv, **kwargs) -> None:\n';D+=E+' ...\n\n';J.write(D)
150
+ J.write(D);L.write_object_stub(J,a,'{0}.{1}'.format(obj_name,C),E+' ',O+1);D=E+' def __init__(self, *argv, **kwargs) -> None:\n';D+=E+' ...\n\n';J.write(D)
150
151
  elif any(A in I for A in[A0,z,'closure']):
151
152
  T=V;U=B
152
153
  if O>0:U='self, '
@@ -159,14 +160,13 @@ class Stubber:
159
160
  if G in(x,v,w,y,'bytearray','bytes'):
160
161
  if C.upper()==C:D='{0}{1}: Final[{3}] = {2}\n'.format(E,C,H,G)
161
162
  else:D=X.format(E,C,H,G)
162
- elif G in(g,f,e):c={g:'{}',f:'[]',e:'()'};D=X.format(E,C,c[G],G)
163
- elif G in('object','set','frozenset','Pin',Y):
164
- if G==Y:G='Generator'
165
- D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
163
+ elif G in(g,f,e):b={g:'{}',f:'[]',e:'()'};D=X.format(E,C,b[G],G)
164
+ elif G in('object','set','frozenset','Pin'):D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
165
+ elif G=='generator':G='Generator';D='{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n'.format(E,C,G,I,H)
166
166
  else:
167
167
  G=V
168
- if K in H:H=H.split(K)[0]+Z
169
- if K in H:H=H.split(K)[0]+Z
168
+ if K in H:H=H.split(K)[0]+Y
169
+ if K in H:H=H.split(K)[0]+Y
170
170
  D='{0}{1}: {2} ## {3} = {4}\n'.format(E,C,G,I,H)
171
171
  J.write(D)
172
172
  else:J.write("# all other, type = '{0}'\n".format(I));J.write(E+C+' # type: Incomplete\n')
@@ -175,13 +175,13 @@ class Stubber:
175
175
  A=self._fwid;B=' .()/\\:$'
176
176
  for C in B:A=A.replace(C,'_')
177
177
  return A
178
- def clean(C,path=E):
179
- if path is E:path=C.path
178
+ def clean(C,path=B):
179
+ if not path:path=C.path
180
180
  A.info('Clean/remove files in folder: {}'.format(path))
181
- try:os.stat(path);F=os.listdir(path)
181
+ try:os.stat(path);E=os.listdir(path)
182
182
  except(D,I):return
183
- for G in F:
184
- B=i.format(path,G)
183
+ for F in E:
184
+ B=i.format(path,F)
185
185
  try:os.remove(B)
186
186
  except D:
187
187
  try:C.clean(B);os.rmdir(B)
@@ -189,32 +189,32 @@ class Stubber:
189
189
  def report_start(B,filename=j):
190
190
  H='firmware';B._json_name=i.format(B.path,filename);B._json_first=T;X(B._json_name);A.info('Report file: {}'.format(B._json_name));F.collect()
191
191
  try:
192
- with M(B._json_name,h)as G:G.write('{');G.write(dumps({H:B.info})[1:-1]);G.write(k);G.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);G.write(k);G.write('"modules" :[\n')
193
- except D as I:A.error(A1);B._json_name=E;raise I
192
+ with M(B._json_name,h)as E:E.write('{');E.write(dumps({H:B.info})[1:-1]);E.write(k);E.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);E.write(k);E.write('"modules" :[\n')
193
+ except D as I:A.error(A1);B._json_name=G;raise I
194
194
  def report_add(B,module_name,stub_file):
195
195
  if not B._json_name:raise s(A2)
196
196
  try:
197
197
  with M(B._json_name,'a')as C:
198
198
  if not B._json_first:C.write(k)
199
199
  else:B._json_first=H
200
- E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
200
+ F='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',E));C.write(F)
201
201
  except D:A.error(A1)
202
202
  def report_end(B):
203
203
  if not B._json_name:raise s(A2)
204
204
  with M(B._json_name,'a')as C:C.write('\n]}')
205
205
  A.info('Path: {}'.format(B.path))
206
206
  def X(path):
207
- B=E=0
207
+ B=F=0
208
208
  while B!=-1:
209
- B=path.find(G,E)
209
+ B=path.find(E,F)
210
210
  if B!=-1:
211
211
  C=path[0]if B==0 else path[:B]
212
212
  try:I=os.stat(C)
213
- except D as F:
214
- if F.args[0]==A3:
213
+ except D as G:
214
+ if G.args[0]in[A3,A4]:
215
215
  try:A.debug('Create folder {}'.format(C));os.mkdir(C)
216
216
  except D as H:A.error('failed to create folder {}'.format(C));raise H
217
- E=B+1
217
+ F=B+1
218
218
  def Y(s):
219
219
  C=' on '
220
220
  if not s:return B
@@ -225,18 +225,18 @@ def Y(s):
225
225
  if not W in s:return B
226
226
  A=s.split(W)[1].split(K)[1];return A
227
227
  def _info():
228
- a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';F='mpy';D='build'
228
+ a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';E='mpy';D='build'
229
229
  try:J=sys.implementation[0]
230
230
  except d:J=sys.implementation.name
231
- A=l({S:J,C:B,D:B,M:B,L:sys.platform,U:'UNKNOWN',P:B,F:B,R:B})
231
+ A=l({S:J,C:B,D:B,M:B,L:sys.platform,U:'UNKNOWN',P:B,E:B,R:B})
232
232
  if A[L].startswith('pyb'):A[L]='stm32'
233
233
  elif A[L]==T:A[L]='windows'
234
234
  elif A[L]=='linux':A[L]=V
235
- try:A[C]=A6(sys.implementation.version)
235
+ try:A[C]=A7(sys.implementation.version)
236
236
  except I:pass
237
- try:K=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[U]=K;A[P]=K.split('with')[-1].strip();A[F]=sys.implementation._mpy if'_mpy'in N(sys.implementation)else sys.implementation.mpy if F in N(sys.implementation)else B
237
+ try:K=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[U]=K;A[P]=K.split('with')[-1].strip();A[E]=sys.implementation._mpy if'_mpy'in N(sys.implementation)else sys.implementation.mpy if E in N(sys.implementation)else B
238
238
  except(I,Q):pass
239
- A[U]=A7()
239
+ A[U]=A8()
240
240
  try:
241
241
  if'uname'in N(os):
242
242
  A[D]=Y(os.uname()[3])
@@ -247,25 +247,25 @@ def _info():
247
247
  try:b=os.uname();A[C]=b.release
248
248
  except(Q,I,d):pass
249
249
  for(c,e,f)in[(X,X,'const'),(Z,Z,'FAT'),(a,'pybricks.hubs','EV3Brick')]:
250
- try:g=__import__(e,E,E,f);A[S]=c;del g;break
250
+ try:g=__import__(e,G,G,f);A[S]=c;del g;break
251
251
  except(O,r):pass
252
252
  if A[S]==a:A['release']='2.0.0'
253
253
  if A[S]==u:
254
254
  A[C]
255
255
  if A[C]and A[C].endswith('.0')and A[C]>='1.10.0'and A[C]<='1.19.9':A[C]=A[C][:-2]
256
- if F in A and A[F]:
257
- G=int(A[F])
258
- try:H=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][G>>10]
256
+ if E in A and A[E]:
257
+ F=int(A[E])
258
+ try:H=[G,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][F>>10]
259
259
  except Q:H='unknown'
260
260
  if H:A[R]=H
261
- A[F]='v{}.{}'.format(G&255,G>>8&3)
261
+ A[E]='v{}.{}'.format(F&255,F>>8&3)
262
262
  if A[D]and not A[C].endswith(W):A[C]=A[C]+W
263
263
  A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
264
- def A6(version):
264
+ def A7(version):
265
265
  A=version;B=K.join([c(A)for A in A[:3]])
266
266
  if R(A)>3 and A[3]:B+=V+A[3]
267
267
  return B
268
- def A7():
268
+ def A8():
269
269
  try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
270
270
  except O:A.warning('BOARDNAME not found');C=B
271
271
  return C
@@ -273,7 +273,7 @@ def get_root():
273
273
  try:A=os.getcwd()
274
274
  except(D,I):A=K
275
275
  B=A
276
- for B in['/remote','/sd','/flash',G,A,K]:
276
+ for B in['/remote','/sd','/flash',E,A,K]:
277
277
  try:C=os.stat(B);break
278
278
  except D:continue
279
279
  return B
@@ -295,8 +295,8 @@ def n():
295
295
  try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
296
296
  except(o,I):return T
297
297
  a='modulelist.done'
298
- def A8(skip=0):
299
- for E in A5:
298
+ def A9(skip=0):
299
+ for E in A6:
300
300
  B=E+'/modulelist.txt'
301
301
  if not Z(B):continue
302
302
  try:
@@ -311,9 +311,9 @@ def A8(skip=0):
311
311
  yield A
312
312
  break
313
313
  except D:pass
314
- def A9(done):
314
+ def AA(done):
315
315
  with M(a,h)as A:A.write(c(done)+'\n')
316
- def AA():
316
+ def AB():
317
317
  A=0
318
318
  try:
319
319
  with M(a)as B:A=int(B.readline().strip())
@@ -325,11 +325,11 @@ def main():
325
325
  else:A.info('Starting new run')
326
326
  stubber=Stubber(path=read_path());B=0
327
327
  if not C:stubber.clean();stubber.report_start(j)
328
- else:B=AA();stubber._json_name=i.format(stubber.path,j)
329
- for E in A8(B):
328
+ else:B=AB();stubber._json_name=i.format(stubber.path,j)
329
+ for E in A9(B):
330
330
  try:stubber.create_one_stub(E)
331
331
  except p:D.reset()
332
- F.collect();B+=1;A9(B)
332
+ F.collect();B+=1;AA(B)
333
333
  P('All modules have been processed, Finalizing report');stubber.report_end()
334
334
  if __name__=='__main__'or n():
335
335
  if not Z('no_auto_stubber.txt'):
Binary file
@@ -9,7 +9,7 @@
9
9
  - cross compilation, using mpy-cross,
10
10
  to avoid the compilation step on the micropython device
11
11
 
12
- This variant was generated from createstubs.py by micropython-stubber v1.24.0
12
+ This variant was generated from createstubs.py by micropython-stubber v1.24.3
13
13
  """
14
14
 
15
15
  # Copyright (c) 2019-2024 Jos Verlinde
@@ -35,7 +35,8 @@ except ImportError:
35
35
  from ucollections import OrderedDict # type: ignore
36
36
 
37
37
  __version__ = "v1.24.0"
38
- ENOENT = 2
38
+ ENOENT = 2 # on most ports
39
+ ENOMESSAGE = 44 # on pyscript
39
40
  _MAX_CLASS_LEVEL = 2 # Max class nesting
40
41
  LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
41
42
 
@@ -82,7 +83,7 @@ logging.basicConfig(level=logging.INFO)
82
83
  class Stubber:
83
84
  "Generate stubs for modules in firmware"
84
85
 
85
- def __init__(self, path: str = None, firmware_id: str = None): # type: ignore
86
+ def __init__(self, path: str = "", firmware_id: str = ""): # type: ignore
86
87
  try:
87
88
  if os.uname().release == "1.13.0" and os.uname().version < "v1.13-103": # type: ignore
88
89
  raise NotImplementedError("MicroPython 1.13.0 cannot be stubbed")
@@ -241,7 +242,7 @@ class Stubber:
241
242
  info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
242
243
  s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
243
244
  fp.write(s)
244
- fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
245
+ fp.write("from __future__ import annotations\nfrom typing import Any, Final, Generator\nfrom _typeshed import Incomplete\n\n")
245
246
  self.write_object_stub(fp, new_module, module_name, "")
246
247
 
247
248
  self.report_add(module_name, file_name)
@@ -360,12 +361,16 @@ class Stubber:
360
361
  s = "{0}{1}: {3} = {2}\n".format(indent, item_name, ev[t], t)
361
362
  else:
362
363
  # something else
363
- if t in ("object", "set", "frozenset", "Pin", "generator"): # "FileIO"
364
+ if t in ("object", "set", "frozenset", "Pin"): # "FileIO"
364
365
  # https://docs.python.org/3/tutorial/classes.html#item_instance-objects
365
366
  # use these types for the attribute
366
- if t == "generator":
367
- t = "Generator"
368
367
  s = "{0}{1}: {2} ## = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
368
+ elif t == "generator":
369
+ # either a normal or async Generator function
370
+ t = "Generator"
371
+ s = "{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n".format(
372
+ indent, item_name, t, item_type_txt, item_repr
373
+ )
369
374
  else:
370
375
  # Requires Python 3.6 syntax, which is OK for the stubs/pyi
371
376
  t = "Incomplete"
@@ -400,9 +405,9 @@ class Stubber:
400
405
  s = s.replace(c, "_")
401
406
  return s
402
407
 
403
- def clean(self, path: str = None): # type: ignore
408
+ def clean(self, path: str = ""): # type: ignore
404
409
  "Remove all files from the stub folder"
405
- if path is None:
410
+ if not path:
406
411
  path = self.path
407
412
  log.info("Clean/remove files in folder: {}".format(path))
408
413
  try:
@@ -483,7 +488,7 @@ def ensure_folder(path: str):
483
488
  _ = os.stat(p)
484
489
  except OSError as e:
485
490
  # folder does not exist
486
- if e.args[0] == ENOENT:
491
+ if e.args[0] in [ENOENT, ENOMESSAGE]:
487
492
  try:
488
493
  log.debug("Create folder {}".format(p))
489
494
  os.mkdir(p)
@@ -712,11 +717,11 @@ def is_micropython() -> bool:
712
717
 
713
718
  # b) https://docs.micropython.org/en/latest/genrst/builtin_types.html#bytes-with-keywords-not-implemented
714
719
  # Micropython: NotImplementedError
715
- b = bytes("abc", encoding="utf8") # type: ignore # lgtm [py/unused-local-variable]
720
+ b = bytes("abc", encoding="utf8") # type: ignore
716
721
 
717
722
  # c) https://docs.micropython.org/en/latest/genrst/core_language.html#function-objects-do-not-have-the-module-attribute
718
723
  # Micropython: AttributeError
719
- c = is_micropython.__module__ # type: ignore # lgtm [py/unused-local-variable]
724
+ c = is_micropython.__module__ # type: ignore
720
725
  return False
721
726
  except (NotImplementedError, AttributeError):
722
727
  return True