setta 0.0.15.dev3__py3-none-any.whl → 0.0.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of setta might be problematic. Click here for more details.

setta/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.0.15.dev3"
1
+ __version__ = "0.0.16"
@@ -313,7 +313,7 @@ class Exporter:
313
313
  (
314
314
  used_params,
315
315
  unused_params,
316
- positionalOnlyParams,
316
+ passingStyles,
317
317
  ) = self.export_section_params(id)
318
318
 
319
319
  selected_item_ev_refs = get_selected_item_ev_refs(self.p, id)
@@ -334,7 +334,7 @@ class Exporter:
334
334
  "callable": callable,
335
335
  "usedParams": used_params,
336
336
  "unusedParams": unused_params,
337
- "positionalOnlyParams": positionalOnlyParams,
337
+ "passingStyles": passingStyles,
338
338
  }
339
339
  info["dependencies"] = [*used_params, *used_ref_var_names]
340
340
  info["ref_var_name_positions"] = ref_var_name_positions
@@ -397,7 +397,7 @@ class Exporter:
397
397
  (
398
398
  used_params,
399
399
  unused_params,
400
- positionalOnlyParams,
400
+ passingStyles,
401
401
  ) = self.export_section_params(id)
402
402
  info = {
403
403
  "sectionId": id,
@@ -407,7 +407,7 @@ class Exporter:
407
407
  "callable": None,
408
408
  "usedParams": used_params,
409
409
  "unusedParams": unused_params,
410
- "positionalOnlyParams": positionalOnlyParams,
410
+ "passingStyles": passingStyles,
411
411
  },
412
412
  "dependencies": used_params,
413
413
  "ref_var_name_positions": [], # has to be populated when the code is generated
@@ -424,7 +424,7 @@ class Exporter:
424
424
  var_names = [x for x in var_names if x]
425
425
  used_params = []
426
426
  unused_params = []
427
- positionalOnlyParams = set()
427
+ passingStyles = {}
428
428
  for v in var_names:
429
429
  if no_entered_value(self.output[v]["value"]):
430
430
  unused_params.append(v)
@@ -432,12 +432,10 @@ class Exporter:
432
432
  used_params.append(v)
433
433
 
434
434
  curr_param_info_id = self.output[v]["paramInfoId"]
435
- positionalOnly = self.p["codeInfo"][curr_param_info_id].get(
436
- "positionalOnly", False
435
+ passingStyles[v] = self.p["codeInfo"][curr_param_info_id].get(
436
+ "passingStyle", None
437
437
  )
438
- if positionalOnly:
439
- positionalOnlyParams.add(v)
440
- return used_params, unused_params, positionalOnlyParams
438
+ return used_params, unused_params, passingStyles
441
439
 
442
440
  def export_param(self, section_id, id):
443
441
  codeInfo = self.p["codeInfo"][id]
@@ -2,7 +2,7 @@ from setta.code_gen.export_selected import get_gen_code_template_var
2
2
  from setta.code_gen.python.make_parseable import make_parseable
3
3
  from setta.utils.utils import replace_at_positions
4
4
 
5
- from ...utils.constants import C
5
+ from ...utils.constants import C, ParameterPassingStyle
6
6
  from ..utils import push_var_deep
7
7
  from .ast_utils import find_missing_imports, find_top_level_symbols
8
8
 
@@ -12,13 +12,22 @@ def get_import_text(code, chars_before_template_var):
12
12
  return f"\n{chars_before_template_var}".join(imports)
13
13
 
14
14
 
15
- def get_mappings(var_names, selected, is_dict, positionalOnlyParams=None):
15
+ def get_mappings(var_names, selected, is_dict=False, passingStyles=None):
16
+ if passingStyles is None:
17
+ passingStyles = {}
16
18
  output = ""
17
19
  relative_positions = []
18
20
  curr_position = 0
19
21
  for idx, v in enumerate(var_names):
20
22
  prefix = "" if idx == 0 else ", "
21
- if is_dict or v not in positionalOnlyParams:
23
+ if passingStyles.get(v) == ParameterPassingStyle.ARGS:
24
+ prefix = "*"
25
+ elif passingStyles.get(v) == ParameterPassingStyle.KWARGS:
26
+ prefix = "**"
27
+ elif is_dict or (
28
+ passingStyles.get(v) == ParameterPassingStyle.DEFAULT
29
+ or passingStyles.get(v) == ParameterPassingStyle.KEYWORD_ONLY
30
+ ):
22
31
  var_decl_prefix = var_declaration(
23
32
  selected[v]["name"],
24
33
  v,
@@ -40,14 +49,12 @@ def get_dict_contents(var_names, selected):
40
49
  return get_mappings(var_names, selected, is_dict=True)
41
50
 
42
51
 
43
- def get_callable_params(var_names, positionalOnlyParams, selected):
44
- return get_mappings(
45
- var_names, selected, is_dict=False, positionalOnlyParams=positionalOnlyParams
46
- )
52
+ def get_callable_params(var_names, passingStyles, selected):
53
+ return get_mappings(var_names, selected, passingStyles=passingStyles)
47
54
 
48
55
 
49
56
  def get_list_of_vars(var_names):
50
- return get_mappings(var_names, None, is_dict=False, positionalOnlyParams=var_names)
57
+ return get_mappings(var_names, None)
51
58
 
52
59
 
53
60
  def get_boolean(value):
@@ -97,7 +104,7 @@ def get_value(x, selected):
97
104
  prefix_len = len(prefix)
98
105
  else:
99
106
  output, relative_positions = get_callable_params(
100
- x["value"]["usedParams"], x["value"]["positionalOnlyParams"], selected
107
+ x["value"]["usedParams"], x["value"]["passingStyles"], selected
101
108
  )
102
109
  prefix = f"{x['value']['callable']}("
103
110
  output = f"{prefix}{output})"
@@ -2,6 +2,8 @@ import re
2
2
 
3
3
  import docstring_parser
4
4
 
5
+ from setta.utils.constants import ParameterPassingStyle
6
+
5
7
 
6
8
  def process_signature_help_response(response):
7
9
  content = None
@@ -40,13 +42,21 @@ def wrapper_parse_signature(signature, docstring, get_proposed_params):
40
42
  params = get_proposed_params(signature, docstring)
41
43
  param_info_list = []
42
44
  positional_only_indicator_idx = -1
45
+ keyword_only_indicator_idx = -1
43
46
 
44
- for idx, (name, default, description) in enumerate(params):
47
+ for idx, (name, _, _) in enumerate(params):
45
48
  if name == "/":
46
49
  positional_only_indicator_idx = idx
50
+ if name == "*":
51
+ keyword_only_indicator_idx = idx
52
+
53
+ for idx, (name, default, description) in enumerate(params):
54
+ if name in [None, "/", "*", "", "..."]:
47
55
  continue
48
- if name in [None, "", "*", "..."]:
49
- continue
56
+
57
+ passingStyle = get_passing_style(
58
+ idx, positional_only_indicator_idx, keyword_only_indicator_idx, name
59
+ )
50
60
 
51
61
  if not default:
52
62
  default = ""
@@ -57,16 +67,13 @@ def wrapper_parse_signature(signature, docstring, get_proposed_params):
57
67
  # Append parsed information to list
58
68
  param_info_list.append(
59
69
  {
60
- "name": name,
70
+ "name": name.lstrip("*"),
61
71
  "defaultVal": default,
62
72
  "description": description,
63
- "positionalOnly": False,
73
+ "passingStyle": passingStyle,
64
74
  }
65
75
  )
66
76
 
67
- for idx in range(0, positional_only_indicator_idx):
68
- param_info_list[idx]["positionalOnly"] = True
69
-
70
77
  return param_info_list
71
78
 
72
79
 
@@ -79,21 +86,55 @@ def get_pyright_param_proposals(signature, _):
79
86
  params = [(p["label"], p["documentation"]["value"]) for p in parameters]
80
87
  proposals = []
81
88
  for param, description in params:
82
- # Extract parameter name and default value
83
- if param.startswith("/"):
84
- proposals.append((param, None, None))
85
- continue
86
- parts = param.split("=")
87
- name = extract_variable_name(parts[0].strip())
88
- default = parts[1].strip() if len(parts) > 1 else None
89
+ name, _, default = parse_param_name(param)
89
90
  proposals.append((name, default, description))
90
91
 
91
92
  return proposals
92
93
 
93
94
 
94
- def extract_variable_name(code_string):
95
- # Find potential variable names
96
- potential_names = re.findall(r"\b[a-zA-Z_]\w*\b", code_string)
95
+ def parse_param_name(param_string):
96
+ # Special cases for / and *
97
+ if param_string in ["/", "*"]:
98
+ return param_string, None, None
99
+
100
+ # Extract default value if present
101
+ default_value = None
102
+ if "=" in param_string:
103
+ param_string, default_part = param_string.split("=", 1)
104
+ default_value = default_part.strip()
105
+
106
+ # Extract type annotation if present
107
+ type_annotation = None
108
+ if ":" in param_string:
109
+ param_string, type_part = param_string.split(":", 1)
110
+ type_annotation = type_part.strip()
97
111
 
98
- # Return the first valid identifier
99
- return next((name for name in potential_names if name.isidentifier()), None)
112
+ # Variable name is what remains, trimmed of whitespace
113
+ name = extract_variable_name(param_string)
114
+
115
+ return name, type_annotation, default_value
116
+
117
+
118
+ def extract_variable_name(code_string):
119
+ # Find potential variable names including * and ** prefixes
120
+ potential_names = re.findall(r"\*{1,2}?[a-zA-Z_]\w*|\b[a-zA-Z_]\w*\b", code_string)
121
+
122
+ # For names with * or **, we don't need to check isidentifier() since they're not standard identifiers
123
+ # Just return the first match
124
+ if potential_names:
125
+ return potential_names[0]
126
+ return None
127
+
128
+
129
+ def get_passing_style(
130
+ idx, positional_only_indicator_idx, keyword_only_indicator_idx, name
131
+ ):
132
+ if name.startswith("**"): # Check for **kwargs first
133
+ return ParameterPassingStyle.KWARGS
134
+ if name.startswith("*"): # Check for *args second
135
+ return ParameterPassingStyle.ARGS
136
+ if 0 <= idx < positional_only_indicator_idx: # Then check position
137
+ return ParameterPassingStyle.POSITIONAL_ONLY
138
+ if keyword_only_indicator_idx > -1 and idx > keyword_only_indicator_idx:
139
+ return ParameterPassingStyle.KEYWORD_ONLY
140
+ return ParameterPassingStyle.DEFAULT
@@ -13,6 +13,7 @@
13
13
  "loadShortcut": "Mod + L",
14
14
  "searchShortcut": "Mod + K",
15
15
  "advancedSearchShortcut": "Mod + P",
16
+ "commandPaletteShortcut": "Mod + Shift + P",
16
17
  "resetZoomShortcut": "Mod + Comma",
17
18
  "copyShortcut": "Mod + C",
18
19
  "pasteShortcut": "Mod + V",
@@ -90,7 +90,7 @@
90
90
  "rcType": "parameter",
91
91
  "defaultVal": "",
92
92
  "description": "",
93
- "positionalOnly": false,
93
+ "passingStyle": "DEFAULT",
94
94
  "isPinned": false,
95
95
  "isFrozen": false,
96
96
  "isSelected": false,