varname 0.13.2__py3-none-any.whl → 0.13.4__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- varname/__init__.py +1 -1
- varname/core.py +5 -0
- varname/helpers.py +14 -3
- varname/utils.py +114 -55
- {varname-0.13.2.dist-info → varname-0.13.4.dist-info}/METADATA +1 -1
- varname-0.13.4.dist-info/RECORD +10 -0
- varname-0.13.2.dist-info/RECORD +0 -10
- {varname-0.13.2.dist-info → varname-0.13.4.dist-info}/LICENSE +0 -0
- {varname-0.13.2.dist-info → varname-0.13.4.dist-info}/WHEEL +0 -0
varname/__init__.py
CHANGED
varname/core.py
CHANGED
@@ -291,6 +291,11 @@ def nameof(
|
|
291
291
|
VarnameRetrievingError: When the callee's node cannot be retrieved or
|
292
292
|
trying to retrieve the full name of non attribute series calls.
|
293
293
|
"""
|
294
|
+
warnings.warn(
|
295
|
+
"`nameof` is deprecated and will be removed in the future. "
|
296
|
+
"Please use `argname` instead.",
|
297
|
+
DeprecationWarning,
|
298
|
+
)
|
294
299
|
# Frame is anyway used in get_node
|
295
300
|
frameobj = IgnoreList.create(
|
296
301
|
ignore_lambda=False,
|
varname/helpers.py
CHANGED
@@ -153,7 +153,12 @@ class Wrapper:
|
|
153
153
|
)
|
154
154
|
|
155
155
|
|
156
|
-
def jsobj(
|
156
|
+
def jsobj(
|
157
|
+
*args: Any,
|
158
|
+
vars_only: bool = True,
|
159
|
+
frame: int = 1,
|
160
|
+
**kwargs: Any,
|
161
|
+
) -> Dict[str, Any]:
|
157
162
|
"""A wrapper to create a JavaScript-like object
|
158
163
|
|
159
164
|
When an argument is passed as positional argument, the name of the variable
|
@@ -171,13 +176,19 @@ def jsobj(*args: Any, vars_only: bool = True, **kwargs: Any) -> Dict[str, Any]:
|
|
171
176
|
|
172
177
|
Args:
|
173
178
|
*args: The positional arguments
|
174
|
-
**kwargs: The keyword arguments
|
175
179
|
vars_only: Whether to only include variables in the output
|
180
|
+
frame: The call stack index. You can understand this as the number of
|
181
|
+
wrappers around this function - 1.
|
182
|
+
**kwargs: The keyword arguments
|
176
183
|
|
177
184
|
Returns:
|
178
185
|
A dict-like object
|
179
186
|
"""
|
180
|
-
argnames: Tuple[str, ...] = argname(
|
187
|
+
argnames: Tuple[str, ...] = argname(
|
188
|
+
"args",
|
189
|
+
vars_only=vars_only,
|
190
|
+
frame=frame,
|
191
|
+
) # type: ignore
|
181
192
|
out = dict(zip(argnames, args))
|
182
193
|
out.update(kwargs)
|
183
194
|
return out
|
varname/utils.py
CHANGED
@@ -74,6 +74,7 @@ else: # pragma: no cover
|
|
74
74
|
ASSIGN_TYPES = (ast.Assign, ast.AnnAssign)
|
75
75
|
AssignType = Union[ASSIGN_TYPES] # type: ignore
|
76
76
|
|
77
|
+
PY311 = sys.version_info >= (3, 11)
|
77
78
|
MODULE_IGNORE_ID_NAME = "__varname_ignore_id__"
|
78
79
|
|
79
80
|
|
@@ -281,6 +282,7 @@ def bytecode_nameof(code: CodeType, offset: int) -> str:
|
|
281
282
|
"CALL_FUNCTION",
|
282
283
|
"CALL_METHOD",
|
283
284
|
"CALL",
|
285
|
+
"CALL_KW",
|
284
286
|
):
|
285
287
|
raise VarnameRetrievingError("Did you call 'nameof' in a weird way?")
|
286
288
|
|
@@ -290,7 +292,7 @@ def bytecode_nameof(code: CodeType, offset: int) -> str:
|
|
290
292
|
current_instruction_index -= 1
|
291
293
|
name_instruction = instructions[current_instruction_index]
|
292
294
|
|
293
|
-
if name_instruction.opname
|
295
|
+
if name_instruction.opname in ("KW_NAMES", "LOAD_CONST"): # LOAD_CONST python 3.13
|
294
296
|
raise pos_only_error
|
295
297
|
|
296
298
|
if not name_instruction.opname.startswith("LOAD_"):
|
@@ -533,22 +535,38 @@ def _(node: Union[ast.Attribute, ast.Subscript]) -> ast.Call:
|
|
533
535
|
|
534
536
|
# x[1], x.a
|
535
537
|
if isinstance(node.ctx, ast.Load):
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
538
|
+
if PY311:
|
539
|
+
return ast.Call(
|
540
|
+
func=ast.Attribute(
|
541
|
+
value=node.value,
|
542
|
+
attr=(
|
543
|
+
"__getitem__"
|
544
|
+
if isinstance(node, ast.Subscript)
|
545
|
+
else "__getattr__"
|
546
|
+
),
|
547
|
+
ctx=ast.Load(),
|
548
|
+
**nodemeta,
|
543
549
|
),
|
544
|
-
|
545
|
-
|
546
|
-
)
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
550
|
+
args=[keynode],
|
551
|
+
keywords=[],
|
552
|
+
)
|
553
|
+
else:
|
554
|
+
return ast.Call( # type: ignore
|
555
|
+
func=ast.Attribute(
|
556
|
+
value=node.value,
|
557
|
+
attr=(
|
558
|
+
"__getitem__"
|
559
|
+
if isinstance(node, ast.Subscript)
|
560
|
+
else "__getattr__"
|
561
|
+
),
|
562
|
+
ctx=ast.Load(),
|
563
|
+
**nodemeta,
|
564
|
+
),
|
565
|
+
args=[keynode],
|
566
|
+
keywords=[],
|
567
|
+
starargs=None,
|
568
|
+
kwargs=None,
|
569
|
+
)
|
552
570
|
|
553
571
|
# x[a] = b, x.a = b
|
554
572
|
if (
|
@@ -564,22 +582,38 @@ def _(node: Union[ast.Attribute, ast.Subscript]) -> ast.Call:
|
|
564
582
|
)
|
565
583
|
)
|
566
584
|
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
585
|
+
if PY311:
|
586
|
+
return ast.Call(
|
587
|
+
func=ast.Attribute(
|
588
|
+
value=node.value,
|
589
|
+
attr=(
|
590
|
+
"__setitem__"
|
591
|
+
if isinstance(node, ast.Subscript)
|
592
|
+
else "__setattr__"
|
593
|
+
),
|
594
|
+
ctx=ast.Load(),
|
595
|
+
**nodemeta,
|
574
596
|
),
|
575
|
-
|
576
|
-
|
577
|
-
)
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
597
|
+
args=[keynode, node.parent.value], # type: ignore
|
598
|
+
keywords=[],
|
599
|
+
)
|
600
|
+
else:
|
601
|
+
return ast.Call(
|
602
|
+
func=ast.Attribute(
|
603
|
+
value=node.value,
|
604
|
+
attr=(
|
605
|
+
"__setitem__"
|
606
|
+
if isinstance(node, ast.Subscript)
|
607
|
+
else "__setattr__"
|
608
|
+
),
|
609
|
+
ctx=ast.Load(),
|
610
|
+
**nodemeta,
|
611
|
+
),
|
612
|
+
args=[keynode, node.parent.value], # type: ignore
|
613
|
+
keywords=[],
|
614
|
+
starargs=None,
|
615
|
+
kwargs=None,
|
616
|
+
)
|
583
617
|
|
584
618
|
|
585
619
|
@reconstruct_func_node.register(ast.Compare)
|
@@ -593,18 +627,30 @@ def _(node: ast.Compare) -> ast.Call:
|
|
593
627
|
"lineno": node.lineno,
|
594
628
|
"col_offset": node.col_offset,
|
595
629
|
}
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
630
|
+
if PY311:
|
631
|
+
return ast.Call(
|
632
|
+
func=ast.Attribute(
|
633
|
+
value=node.left,
|
634
|
+
attr=CMP2MAGIC[type(node.ops[0])],
|
635
|
+
ctx=ast.Load(),
|
636
|
+
**nodemeta,
|
637
|
+
),
|
638
|
+
args=[node.comparators[0]],
|
639
|
+
keywords=[],
|
640
|
+
)
|
641
|
+
else:
|
642
|
+
return ast.Call( # type: ignore
|
643
|
+
func=ast.Attribute(
|
644
|
+
value=node.left,
|
645
|
+
attr=CMP2MAGIC[type(node.ops[0])],
|
646
|
+
ctx=ast.Load(),
|
647
|
+
**nodemeta,
|
648
|
+
),
|
649
|
+
args=[node.comparators[0]],
|
650
|
+
keywords=[],
|
651
|
+
starargs=None,
|
652
|
+
kwargs=None,
|
653
|
+
)
|
608
654
|
|
609
655
|
|
610
656
|
@reconstruct_func_node.register(ast.BinOp)
|
@@ -614,18 +660,31 @@ def _(node: ast.BinOp) -> ast.Call:
|
|
614
660
|
"lineno": node.lineno,
|
615
661
|
"col_offset": node.col_offset,
|
616
662
|
}
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
663
|
+
|
664
|
+
if PY311:
|
665
|
+
return ast.Call(
|
666
|
+
func=ast.Attribute(
|
667
|
+
value=node.left,
|
668
|
+
attr=OP2MAGIC[type(node.op)],
|
669
|
+
ctx=ast.Load(),
|
670
|
+
**nodemeta,
|
671
|
+
),
|
672
|
+
args=[node.right],
|
673
|
+
keywords=[],
|
674
|
+
)
|
675
|
+
else:
|
676
|
+
return ast.Call( # type: ignore
|
677
|
+
func=ast.Attribute(
|
678
|
+
value=node.left,
|
679
|
+
attr=OP2MAGIC[type(node.op)],
|
680
|
+
ctx=ast.Load(),
|
681
|
+
**nodemeta,
|
682
|
+
),
|
683
|
+
args=[node.right],
|
684
|
+
keywords=[],
|
685
|
+
starargs=None,
|
686
|
+
kwargs=None,
|
687
|
+
)
|
629
688
|
|
630
689
|
|
631
690
|
def rich_exc_message(msg: str, node: ast.AST, context_lines: int = 4) -> str:
|
@@ -0,0 +1,10 @@
|
|
1
|
+
varname/__init__.py,sha256=Kwx6Bac3gQwx6y-nL8tmkBXotCWDefqnktF_uc3tyVs,369
|
2
|
+
varname/core.py,sha256=HKcvZAIq6gQQlzuBgUsqeM0USZFDJ8pkYdQC9z8uJjs,19474
|
3
|
+
varname/helpers.py,sha256=jZaP-qWQJwi8T2f886eHOj-llXAPHk5SMU6PfVn-9dg,9558
|
4
|
+
varname/ignore.py,sha256=-VC3oqag44y2UlAw0ErYKHotx616qJL3Sjb_5y7Tw1c,14400
|
5
|
+
varname/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
6
|
+
varname/utils.py,sha256=JCOGoLEXq3mQvQeobEyGiP4N2y1_42ULjwPvDn5SNSo,22882
|
7
|
+
varname-0.13.4.dist-info/LICENSE,sha256=3bS8O2tMbBPz8rWmZBAOzkHQjcK-b7KwFHyyghEZ-Ak,1063
|
8
|
+
varname-0.13.4.dist-info/METADATA,sha256=PUOgy7_nnnqyVZvE64E97P5IqHYlMVdeyCoCrIhEWCI,12845
|
9
|
+
varname-0.13.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
10
|
+
varname-0.13.4.dist-info/RECORD,,
|
varname-0.13.2.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
varname/__init__.py,sha256=5liGcc8MtbaaXusFuboC3Xf5rNHQv02YRqvNgd8HX10,369
|
2
|
-
varname/core.py,sha256=nntOVpiavXP0EXijTNF6xIe4mxvz_FRpBjrL9z_JHJ0,19311
|
3
|
-
varname/helpers.py,sha256=x52Fmxx7p9PMa3BFFXRD_zapoeBG0WVVU8S5hnHPh60,9354
|
4
|
-
varname/ignore.py,sha256=-VC3oqag44y2UlAw0ErYKHotx616qJL3Sjb_5y7Tw1c,14400
|
5
|
-
varname/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
6
|
-
varname/utils.py,sha256=ByHbUjbdMlHHckW4y77Jr_DHhkSmk8TabTy3INDJWsY,20971
|
7
|
-
varname-0.13.2.dist-info/LICENSE,sha256=3bS8O2tMbBPz8rWmZBAOzkHQjcK-b7KwFHyyghEZ-Ak,1063
|
8
|
-
varname-0.13.2.dist-info/METADATA,sha256=0LgE9BiDPKtkAeDy7VQGx1DSZyWtzRQdA7gCc_CWHv0,12845
|
9
|
-
varname-0.13.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
10
|
-
varname-0.13.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|