-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_service_overloads.py
40 lines (34 loc) · 1.48 KB
/
create_service_overloads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import importlib
import re
from google.ads.googleads import client
lines = []
with open("service_overloads.txt", "w") as f:
for i, version in enumerate(sorted(client._VALID_API_VERSIONS)):
versions_package = importlib.import_module(f"google.ads.googleads.{version}")
for type in versions_package.__all__:
if type.endswith("Client"):
name = type[: -len("Client")]
lines.append(
f' @overload\n def get_service(self, name: Literal["{name}"], version: _{version.upper()}) -> {version}.{type}: ...'
)
if version == client._DEFAULT_VERSION:
lines.append(
f' @overload\n def get_service(self, name: Literal["{name}"]) -> {version}.{type}: ...'
)
if i < len(client._VALID_API_VERSIONS) - 1:
lines.append("\n")
lines.append(
f' @overload\n def get_service(self, name: str, version: _V = "{client._DEFAULT_VERSION}") -> Any: ...'
)
with open("google-stubs/ads/googleads/client.pyi") as f:
client_pyi = f.read()
lines.insert(0, "# Autogenerated service overloads")
lines.append(" # End of autogenerated service overloads")
client_pyi = re.sub(
"# Autogenerated service overloads.+# End of autogenerated service overloads",
"\n".join(lines),
client_pyi,
flags=re.DOTALL,
)
with open("google-stubs/ads/googleads/client.pyi", mode="w") as f:
f.write(client_pyi)