MCPcopy Index your code
hub / github.com/microsoft/playwright-python / generate

Function generate

scripts/generate_sync_api.py:42–132  ·  view source on GitHub ↗
(t: Any)

Source from the content-addressed store, hash-verified

40
41
42def generate(t: Any) -> None:
43 print("")
44 class_name = short_name(t)
45 base_class = t.__bases__[0].__name__
46 if class_name in ["Page", "BrowserContext", "Browser", "Disposable"]:
47 base_sync_class = "SyncContextManager"
48 elif base_class in ["ChannelOwner", "object", "AssertionsBase"]:
49 base_sync_class = "SyncBase"
50 else:
51 base_sync_class = base_class
52 print(f"class {class_name}({base_sync_class}):")
53 print("")
54 documentation_provider.print_events(class_name)
55 for [name, type] in get_type_hints(t, api_globals).items():
56 print("")
57 print(" @property")
58 print(f" def {name}(self) -> {process_type(type)}:")
59 documentation_provider.print_entry(class_name, name, {"return": type}, True)
60 [prefix, suffix] = return_value(type)
61 prefix = " return " + prefix + f"self._impl_obj.{name}"
62 print(f"{prefix}{suffix}")
63 for [name, value] in t.__dict__.items():
64 if name.startswith("_"):
65 continue
66 if str(value).startswith("<property"):
67 value = value.fget
68 print("")
69 print(" @property")
70 print(
71 f" def {name}({signature(value, len(name) + 9)}) -> {return_type(value)}:"
72 )
73 documentation_provider.print_entry(
74 class_name, name, get_type_hints(value, api_globals), True
75 )
76 [prefix, suffix] = return_value(
77 get_type_hints(value, api_globals)["return"]
78 )
79 prefix = " return " + prefix + f"self._impl_obj.{name}"
80 print(f"{prefix}{arguments(value, len(prefix))}{suffix}")
81 for [name, value] in t.__dict__.items():
82 if isinstance(value, FunctionType) and "remove_listener" != name:
83 # List of dunder methods to allow without docs
84 allow_without_docs_methods = [
85 "__getitem__",
86 ]
87 if name.startswith("_") and name not in allow_without_docs_methods:
88 continue
89 is_async = inspect.iscoroutinefunction(value)
90 return_type_value = return_type(value)
91 return_type_value = re.sub(r"\"([^\"]+)Impl\"", r"\1", return_type_value)
92 return_type_value = return_type_value.replace(
93 '"Disposable"', '"SyncContextManager"'
94 ).replace('"DisposableStub"', '"SyncContextManager"')
95 print("")
96 if name in ("expect_event", "wait_for_event"):
97 documentation_provider.print_event_overloads(class_name, name)
98 print(
99 f" def {name}({signature(value, len(name) + 9)}) -> {return_type_value}:"

Callers 1

mainFunction · 0.70

Calls 11

short_nameFunction · 0.90
get_type_hintsFunction · 0.90
process_typeFunction · 0.90
return_valueFunction · 0.90
signatureFunction · 0.90
return_typeFunction · 0.90
argumentsFunction · 0.90
print_eventsMethod · 0.80
print_entryMethod · 0.80
print_event_overloadsMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected