-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules_and_functions.py
More file actions
67 lines (47 loc) · 1.35 KB
/
modules_and_functions.py
File metadata and controls
67 lines (47 loc) · 1.35 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Example: Using agent_help() on modules, functions, and methods.
Demonstrates non-class targets:
1. A custom module (this file itself).
2. A stdlib module (pathlib).
3. A function (connect, defined below).
4. A method (Query.execute, defined below).
Run this file to see all outputs:
python examples/modules_and_functions.py
"""
import os
import pathlib
import sys
from agent_readable import agent_help
def connect(host: str, port: int = 5432) -> str:
"""Connect to a database server."""
return f"{host}:{port}"
def disconnect():
"""Close the connection."""
class Query:
"""Build and execute a query."""
def execute(self, sql: str) -> list: # NOSONAR
"""Execute a SQL statement."""
return []
if __name__ == "__main__":
os.environ["PAGER"] = "cat"
print("=== agent_help(this_module) — custom module ===")
print()
print(agent_help(sys.modules[__name__]))
print()
print("=" * 72)
print()
print("=== agent_help(pathlib) — stdlib module ===")
print()
print(agent_help(pathlib))
print()
print("=" * 72)
print()
print("=== agent_help(connect) — function ===")
print()
print(agent_help(connect))
print()
print("=" * 72)
print()
print("=== agent_help(Query.execute) — method ===")
print()
print(agent_help(Query.execute))