polyapi-python 0.3.18.dev3__py3-none-any.whl → 0.3.18.dev5__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.
polyapi/poly_schemas.py CHANGED
@@ -1,8 +1,9 @@
1
1
  import os
2
+ import re
2
3
  import logging
3
4
  import tempfile
4
5
  import shutil
5
- from typing import Any, Dict, List, Tuple
6
+ from typing import Any, Dict, List, Optional, Tuple
6
7
 
7
8
  from polyapi.schema import wrapped_generate_schema_types
8
9
  from polyapi.utils import add_import_to_init, init_the_init, to_func_namespace
@@ -23,7 +24,7 @@ FALLBACK_SPEC_TEMPLATE = """class {name}(TypedDict, total=False):
23
24
  """
24
25
 
25
26
 
26
- def generate_schemas(specs: List[SchemaSpecDto], limit_ids: List[str] = None):
27
+ def generate_schemas(specs: List[SchemaSpecDto], limit_ids: Optional[List[str]] = None):
27
28
  failed_schemas = []
28
29
  successful_schemas = []
29
30
  if limit_ids:
@@ -209,6 +210,44 @@ def add_schema_to_init(full_path: str, spec: SchemaSpecDto):
209
210
  f.write(render_poly_schema(spec) + "\n\n")
210
211
 
211
212
 
213
+ def _fix_typed_dict_imports(code: str) -> str:
214
+ """Move TypedDict/NotRequired from `typing` to `typing_extensions` in generated code.
215
+
216
+ jsonschema_gentypes spits out `from typing import ..., TypedDict, ...` which makes
217
+ typing._TypedDictMeta instances. The deploy validator wants typing_extensions.TypedDict,
218
+ so let's rewrite the imports here before writing schema files to disk.
219
+ """
220
+ lines = code.split('\n')
221
+ new_lines = []
222
+ has_te_import = False
223
+
224
+ for line in lines:
225
+ if re.match(r'from\s+typing_extensions\s+import', line):
226
+ has_te_import = True
227
+ # Ensure TypedDict and NotRequired are in the existing typing_extensions line
228
+ name_set = {n.strip() for n in line.split('import', 1)[1].split(',')}
229
+ name_set |= {'TypedDict', 'NotRequired'}
230
+ new_lines.append(f"from typing_extensions import {', '.join(sorted(name_set))}")
231
+ continue
232
+
233
+ if re.match(r'from\s+typing\s+import', line):
234
+ # Strip TypedDict and NotRequired from the typing import
235
+ names_str = line.split('import', 1)[1]
236
+ names: list[str] = [n.strip() for n in names_str.split(',')]
237
+ names = [n for n in names if n not in ('TypedDict', 'NotRequired', '')]
238
+ if names:
239
+ new_lines.append(f"from typing import {', '.join(names)}")
240
+ # drop the line entirely if nothing is left
241
+ continue
242
+
243
+ new_lines.append(line)
244
+
245
+ result = '\n'.join(new_lines)
246
+ if not has_te_import:
247
+ result = 'from typing_extensions import NotRequired, TypedDict\n' + result
248
+ return result
249
+
250
+
212
251
  def render_poly_schema(spec: SchemaSpecDto) -> str:
213
252
  definition = spec["definition"]
214
253
  if not definition.get("type"):
@@ -216,5 +255,5 @@ def render_poly_schema(spec: SchemaSpecDto) -> str:
216
255
  root, schema_types = wrapped_generate_schema_types(
217
256
  definition, root=spec["name"], fallback_type=Dict
218
257
  )
219
- return schema_types
258
+ return _fix_typed_dict_imports(schema_types)
220
259
  # return FALLBACK_SPEC_TEMPLATE.format(name=spec["name"])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.18.dev3
3
+ Version: 0.3.18.dev5
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: PolyAPI <support@polyapi.io>
6
6
  License: MIT License
@@ -32,7 +32,7 @@ Requires-Dist: requests==2.32.3
32
32
  Requires-Dist: typing_extensions==4.12.2
33
33
  Requires-Dist: jsonschema-gentypes==2.10.0
34
34
  Requires-Dist: pydantic==2.8.0
35
- Requires-Dist: stdlib_list==0.10.0
35
+ Requires-Dist: stdlib_list==0.11.1
36
36
  Requires-Dist: colorama==0.4.4
37
37
  Requires-Dist: python-socketio[asyncio_client]==5.11.1
38
38
  Requires-Dist: truststore==0.8.0
@@ -15,7 +15,7 @@ polyapi/function_cli.py,sha256=kKrecKCDNMmYtcOOCVF2KKOGjFUfWD2TbiVsyYQ84y8,4323
15
15
  polyapi/generate.py,sha256=LzQBm2GKYfAwTsJ36ViLr1ypzrudijj1qR0DRzp-Be0,21764
16
16
  polyapi/http_client.py,sha256=Pd6FYHGB6plWlBbwZD9LPP6FEicdp0wyLWHd_9jxsaY,2273
17
17
  polyapi/parser.py,sha256=pAkeuwp1Kn6bHXiIoj-DuXQ518PztQThIa8vztgsKLQ,21525
18
- polyapi/poly_schemas.py,sha256=fZ6AGvHcOKQJtlrzSuzeBNed5DxPMA2dJGdJvuFCHWM,9066
18
+ polyapi/poly_schemas.py,sha256=JGMQbELPFw4V_0nA0o71WJKFTdxjCGoKqJvIid_Y-a4,10759
19
19
  polyapi/poly_tables.py,sha256=xFxR69dZNmePT9mUz3DvsoreQK7huIa07evEmOSixA0,20271
20
20
  polyapi/prepare.py,sha256=DBlrQu_A0PqdaQ3KlMs-C6PkV3qncatkAiBlC7j2hnk,7441
21
21
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -27,8 +27,8 @@ polyapi/typedefs.py,sha256=mfll-KrngOW0wzbvDNiIDaDkFMwbsT-MY5y5hzWj9RE,5642
27
27
  polyapi/utils.py,sha256=SfzK86nhg1wuGzbI53DEFKJ3JkxZ0yU-CZBd_caKbrQ,15313
28
28
  polyapi/variables.py,sha256=hfSDPGQK6YphNCa9MqE0W88WIFfqCQWgpBDWkExMq-A,7582
29
29
  polyapi/webhook.py,sha256=0ceLwHNjNd2Yx_8MX5jOIxiQ5Lwhy2pe81ProAuKon0,5108
30
- polyapi_python-0.3.18.dev3.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
31
- polyapi_python-0.3.18.dev3.dist-info/METADATA,sha256=RNGfs03dpAf3Gpdd-jbB9Zi524fPNl5s4zV20WpHheM,5915
32
- polyapi_python-0.3.18.dev3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
33
- polyapi_python-0.3.18.dev3.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
34
- polyapi_python-0.3.18.dev3.dist-info/RECORD,,
30
+ polyapi_python-0.3.18.dev5.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
31
+ polyapi_python-0.3.18.dev5.dist-info/METADATA,sha256=zMwyubuUS-fqd9d9JQPaG3csk8oVqjzGkH41zRF0yvo,5915
32
+ polyapi_python-0.3.18.dev5.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
33
+ polyapi_python-0.3.18.dev5.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
34
+ polyapi_python-0.3.18.dev5.dist-info/RECORD,,