symbex 0.3__py3-none-any.whl → 0.3.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- symbex/lib.py +17 -6
- {symbex-0.3.dist-info → symbex-0.3.2.dist-info}/METADATA +2 -2
- symbex-0.3.2.dist-info/RECORD +10 -0
- symbex-0.3.dist-info/RECORD +0 -10
- {symbex-0.3.dist-info → symbex-0.3.2.dist-info}/LICENSE +0 -0
- {symbex-0.3.dist-info → symbex-0.3.2.dist-info}/WHEEL +0 -0
- {symbex-0.3.dist-info → symbex-0.3.2.dist-info}/entry_points.txt +0 -0
- {symbex-0.3.dist-info → symbex-0.3.2.dist-info}/top_level.txt +0 -0
symbex/lib.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import fnmatch
|
2
|
-
from ast import literal_eval, parse, AST, FunctionDef, ClassDef
|
2
|
+
from ast import literal_eval, parse, AST, AsyncFunctionDef, FunctionDef, ClassDef
|
3
3
|
from itertools import zip_longest
|
4
4
|
import textwrap
|
5
5
|
from typing import Iterable, List, Optional, Tuple
|
@@ -13,7 +13,7 @@ def find_symbol_nodes(
|
|
13
13
|
matches = []
|
14
14
|
module = parse(code)
|
15
15
|
for node in module.body:
|
16
|
-
if not isinstance(node, (ClassDef, FunctionDef)):
|
16
|
+
if not isinstance(node, (ClassDef, FunctionDef, AsyncFunctionDef)):
|
17
17
|
continue
|
18
18
|
name = getattr(node, "name", None)
|
19
19
|
if match(name, symbols):
|
@@ -21,7 +21,7 @@ def find_symbol_nodes(
|
|
21
21
|
# If it's a class search its methods too
|
22
22
|
if isinstance(node, ClassDef):
|
23
23
|
for child in node.body:
|
24
|
-
if isinstance(child, FunctionDef):
|
24
|
+
if isinstance(child, (FunctionDef, AsyncFunctionDef)):
|
25
25
|
qualified_name = f"{name}.{child.name}"
|
26
26
|
if match(qualified_name, symbols):
|
27
27
|
matches.append((child, name))
|
@@ -37,7 +37,7 @@ def code_for_node(
|
|
37
37
|
start = None
|
38
38
|
end = None
|
39
39
|
if signatures:
|
40
|
-
if isinstance(node, FunctionDef):
|
40
|
+
if isinstance(node, (FunctionDef, AsyncFunctionDef)):
|
41
41
|
definition, lineno = function_definition(node), node.lineno
|
42
42
|
if class_name:
|
43
43
|
definition = " " + definition
|
@@ -109,7 +109,14 @@ def function_definition(function_node: AST):
|
|
109
109
|
# if defaults has 2 and args has 3 then those
|
110
110
|
# defaults correspond to the last two args
|
111
111
|
defaults = [None] * (len(all_args) - len(function_node.args.defaults))
|
112
|
-
|
112
|
+
for default in function_node.args.defaults:
|
113
|
+
try:
|
114
|
+
value = literal_eval(default)
|
115
|
+
if isinstance(value, str):
|
116
|
+
value = f'"{value}"'
|
117
|
+
except ValueError:
|
118
|
+
value = getattr(default, "id", "...")
|
119
|
+
defaults.append(value)
|
113
120
|
|
114
121
|
arguments = []
|
115
122
|
|
@@ -144,7 +151,11 @@ def function_definition(function_node: AST):
|
|
144
151
|
# None shows as returns.value is None
|
145
152
|
return_annotation = " -> None"
|
146
153
|
|
147
|
-
|
154
|
+
def_ = "def "
|
155
|
+
if isinstance(function_node, AsyncFunctionDef):
|
156
|
+
def_ = "async def "
|
157
|
+
|
158
|
+
return f"{def_}{function_name}({arguments_str}){return_annotation}"
|
148
159
|
|
149
160
|
|
150
161
|
def class_definition(class_def):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: symbex
|
3
|
-
Version: 0.3
|
3
|
+
Version: 0.3.2
|
4
4
|
Summary: Find the Python code for specified symbols
|
5
5
|
Home-page: https://github.com/simonw/symbex
|
6
6
|
Author: Simon Willison
|
@@ -136,7 +136,7 @@ cog.out(
|
|
136
136
|
# File: symbex/cli.py Line: 37
|
137
137
|
def cli(symbols, files, directories, signatures, silent)
|
138
138
|
|
139
|
-
# File: symbex/lib.py Line:
|
139
|
+
# File: symbex/lib.py Line: 161
|
140
140
|
def class_definition(class_def)
|
141
141
|
|
142
142
|
# File: symbex/lib.py Line: 32
|
@@ -0,0 +1,10 @@
|
|
1
|
+
symbex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
symbex/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
|
3
|
+
symbex/cli.py,sha256=tWzT49q-fPN34HQH2sEFHBV3MXFKy9J5eh2EzOo5_CA,2857
|
4
|
+
symbex/lib.py,sha256=_IwiAfr9rCAe4ptdNt6o6MMibLHnwBmqpmgYRdRmEa4,6499
|
5
|
+
symbex-0.3.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
6
|
+
symbex-0.3.2.dist-info/METADATA,sha256=xlQ1koJSuZ6luJeC1WtNrU-D5g-dz82Br1NPYZ3yUXc,5695
|
7
|
+
symbex-0.3.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
8
|
+
symbex-0.3.2.dist-info/entry_points.txt,sha256=YgMSEfEGqNMHM9RysFObH8lkQKVZKyymKLnXbVue_Uk,42
|
9
|
+
symbex-0.3.2.dist-info/top_level.txt,sha256=qwle8HjAaYgpdMIHlJcTcN4gaG4wmDqUvkt54beTBTs,7
|
10
|
+
symbex-0.3.2.dist-info/RECORD,,
|
symbex-0.3.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
symbex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
symbex/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
|
3
|
-
symbex/cli.py,sha256=tWzT49q-fPN34HQH2sEFHBV3MXFKy9J5eh2EzOo5_CA,2857
|
4
|
-
symbex/lib.py,sha256=q8WhjbPLiXuGnbD3scwCvJrqVvs-RHAMbBEXIYyFqeI,6121
|
5
|
-
symbex-0.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
6
|
-
symbex-0.3.dist-info/METADATA,sha256=Yn6vp7j1nWfTn_GYWXmeWhD7NFXHw2OxI3YnpMRVvew,5693
|
7
|
-
symbex-0.3.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
8
|
-
symbex-0.3.dist-info/entry_points.txt,sha256=YgMSEfEGqNMHM9RysFObH8lkQKVZKyymKLnXbVue_Uk,42
|
9
|
-
symbex-0.3.dist-info/top_level.txt,sha256=qwle8HjAaYgpdMIHlJcTcN4gaG4wmDqUvkt54beTBTs,7
|
10
|
-
symbex-0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|