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

Function generate

scripts/generate_async_api.py:38–130  ·  view source on GitHub ↗
(t: Any)

Source from the content-addressed store, hash-verified

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

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