varname 0.13.5__py3-none-any.whl → 0.15.0__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.
- varname/__init__.py +1 -1
- varname/core.py +1 -5
- varname/utils.py +16 -11
- {varname-0.13.5.dist-info → varname-0.15.0.dist-info}/METADATA +22 -12
- varname-0.15.0.dist-info/RECORD +10 -0
- {varname-0.13.5.dist-info → varname-0.15.0.dist-info}/WHEEL +1 -1
- varname-0.13.5.dist-info/RECORD +0 -10
- {varname-0.13.5.dist-info → varname-0.15.0.dist-info}/LICENSE +0 -0
varname/__init__.py
CHANGED
varname/core.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
"""Provide core features for varname"""
|
2
|
+
from __future__ import annotations
|
2
3
|
import ast
|
3
4
|
import re
|
4
5
|
import warnings
|
@@ -291,11 +292,6 @@ def nameof(
|
|
291
292
|
VarnameRetrievingError: When the callee's node cannot be retrieved or
|
292
293
|
trying to retrieve the full name of non attribute series calls.
|
293
294
|
"""
|
294
|
-
warnings.warn(
|
295
|
-
"`nameof` is deprecated and will be removed in the future. "
|
296
|
-
"Please use `argname` instead.",
|
297
|
-
DeprecationWarning,
|
298
|
-
)
|
299
295
|
# Frame is anyway used in get_node
|
300
296
|
frameobj = IgnoreList.create(
|
301
297
|
ignore_lambda=False,
|
varname/utils.py
CHANGED
@@ -20,6 +20,11 @@ from functools import lru_cache, singledispatch
|
|
20
20
|
from types import ModuleType, FunctionType, CodeType, FrameType
|
21
21
|
from typing import Tuple, Union, List, Mapping, Callable, Dict
|
22
22
|
|
23
|
+
if sys.version_info < (3, 10):
|
24
|
+
from typing_extensions import TypeAlias # pragma: no cover
|
25
|
+
else:
|
26
|
+
from typing import TypeAlias
|
27
|
+
|
23
28
|
from executing import Source
|
24
29
|
|
25
30
|
OP2MAGIC = {
|
@@ -63,16 +68,16 @@ IgnoreElemType = Union[
|
|
63
68
|
]
|
64
69
|
IgnoreType = Union[IgnoreElemType, List[IgnoreElemType]]
|
65
70
|
|
66
|
-
ArgSourceType = Union[ast.AST, str]
|
67
|
-
ArgSourceType = Union[ArgSourceType, Tuple[ArgSourceType, ...]]
|
68
|
-
ArgSourceType = Union[ArgSourceType, Mapping[str, ArgSourceType]]
|
71
|
+
ArgSourceType: TypeAlias = Union[ast.AST, str]
|
72
|
+
ArgSourceType: TypeAlias = Union[ArgSourceType, Tuple[ArgSourceType, ...]]
|
73
|
+
ArgSourceType: TypeAlias = Union[ArgSourceType, Mapping[str, ArgSourceType]]
|
69
74
|
|
70
75
|
if sys.version_info >= (3, 8):
|
71
76
|
ASSIGN_TYPES = (ast.Assign, ast.AnnAssign, ast.NamedExpr)
|
72
|
-
AssignType = Union[ASSIGN_TYPES] # type: ignore
|
73
|
-
else: # pragma: no cover
|
77
|
+
AssignType: TypeAlias = Union[ASSIGN_TYPES] # type: ignore
|
78
|
+
else: # pragma: no cover # Python < 3.8
|
74
79
|
ASSIGN_TYPES = (ast.Assign, ast.AnnAssign)
|
75
|
-
AssignType = Union[ASSIGN_TYPES] # type: ignore
|
80
|
+
AssignType: TypeAlias = Union[ASSIGN_TYPES] # type: ignore
|
76
81
|
|
77
82
|
PY311 = sys.version_info >= (3, 11)
|
78
83
|
MODULE_IGNORE_ID_NAME = "__varname_ignore_id__"
|
@@ -163,7 +168,7 @@ def get_node_by_frame(frame: FrameType, raise_exc: bool = True) -> ast.AST:
|
|
163
168
|
exect.node.__frame__ = frame
|
164
169
|
return exect.node
|
165
170
|
|
166
|
-
if exect.source.text and exect.source.tree and raise_exc:
|
171
|
+
if exect.source.text and exect.source.tree and raise_exc: # pragma: no cover
|
167
172
|
raise VarnameRetrievingError(
|
168
173
|
"Couldn't retrieve the call node. "
|
169
174
|
"This may happen if you're using some other AST magic at the "
|
@@ -550,7 +555,7 @@ def _(node: Union[ast.Attribute, ast.Subscript]) -> ast.Call:
|
|
550
555
|
args=[keynode],
|
551
556
|
keywords=[],
|
552
557
|
)
|
553
|
-
else:
|
558
|
+
else: # pragma: no cover
|
554
559
|
return ast.Call( # type: ignore
|
555
560
|
func=ast.Attribute(
|
556
561
|
value=node.value,
|
@@ -597,7 +602,7 @@ def _(node: Union[ast.Attribute, ast.Subscript]) -> ast.Call:
|
|
597
602
|
args=[keynode, node.parent.value], # type: ignore
|
598
603
|
keywords=[],
|
599
604
|
)
|
600
|
-
else:
|
605
|
+
else: # pragma: no cover
|
601
606
|
return ast.Call(
|
602
607
|
func=ast.Attribute(
|
603
608
|
value=node.value,
|
@@ -638,7 +643,7 @@ def _(node: ast.Compare) -> ast.Call:
|
|
638
643
|
args=[node.comparators[0]],
|
639
644
|
keywords=[],
|
640
645
|
)
|
641
|
-
else:
|
646
|
+
else: # pragma: no cover
|
642
647
|
return ast.Call( # type: ignore
|
643
648
|
func=ast.Attribute(
|
644
649
|
value=node.left,
|
@@ -672,7 +677,7 @@ def _(node: ast.BinOp) -> ast.Call:
|
|
672
677
|
args=[node.right],
|
673
678
|
keywords=[],
|
674
679
|
)
|
675
|
-
else:
|
680
|
+
else: # pragma: no cover
|
676
681
|
return ast.Call( # type: ignore
|
677
682
|
func=ast.Attribute(
|
678
683
|
value=node.left,
|
@@ -1,8 +1,7 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: varname
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.15.0
|
4
4
|
Summary: Dark magics about variable names in python.
|
5
|
-
Home-page: https://github.com/pwwang/python-varname
|
6
5
|
License: MIT
|
7
6
|
Author: pwwang
|
8
7
|
Author-email: pwwang@pwwang.com
|
@@ -14,10 +13,13 @@ Classifier: Programming Language :: Python :: 3.9
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
17
17
|
Provides-Extra: all
|
18
|
-
Requires-Dist: asttokens (==
|
18
|
+
Requires-Dist: asttokens (==3.*) ; extra == "all"
|
19
19
|
Requires-Dist: executing (>=2.1,<3.0)
|
20
20
|
Requires-Dist: pure_eval (==0.*) ; extra == "all"
|
21
|
+
Requires-Dist: typing_extensions (>=4.13,<5.0) ; python_version < "3.10"
|
22
|
+
Project-URL: Homepage, https://github.com/pwwang/python-varname
|
21
23
|
Project-URL: Repository, https://github.com/pwwang/python-varname
|
22
24
|
Description-Content-Type: text/markdown
|
23
25
|
|
@@ -44,7 +46,6 @@ Note if you use `python < 3.8`, install `varname < 0.11`
|
|
44
46
|
- Core features:
|
45
47
|
|
46
48
|
- Retrieving names of variables a function/class call is assigned to from inside it, using `varname`.
|
47
|
-
- Retrieving variable names directly, using `nameof`
|
48
49
|
- Detecting next immediate attribute name, using `will`
|
49
50
|
- Fetching argument names/sources passed to a function using `argname`
|
50
51
|
|
@@ -438,22 +439,27 @@ obj.argnames # ['1', '2']
|
|
438
439
|
`varname` is all depending on `executing` package to look for the node.
|
439
440
|
The node `executing` detects is ensured to be the correct one (see [this][19]).
|
440
441
|
|
441
|
-
It partially works with environments where other AST magics apply, including
|
442
|
-
`
|
442
|
+
It partially works with environments where other AST magics apply, including [`exec`][24] function,
|
443
|
+
[`macropy`][21], [`birdseye`][22], [`reticulate`][23] with `R`, etc. Neither
|
443
444
|
`executing` nor `varname` is 100% working with those environments. Use
|
444
445
|
it at your own risk.
|
445
446
|
|
446
447
|
For example:
|
447
448
|
|
448
|
-
- This will not work
|
449
|
+
- This will not work:
|
449
450
|
|
450
451
|
```python
|
452
|
+
from varname import argname
|
453
|
+
|
454
|
+
def getname(x):
|
455
|
+
print(argname("x"))
|
456
|
+
|
451
457
|
a = 1
|
452
|
-
|
458
|
+
exec("getname(a)") # Cannot retrieve the node where the function is called.
|
453
459
|
|
454
|
-
|
455
|
-
|
456
|
-
|
460
|
+
## instead
|
461
|
+
# from varname.helpers import exec_code
|
462
|
+
# exec_code("getname(a)")
|
457
463
|
```
|
458
464
|
|
459
465
|
[1]: https://github.com/pwwang/python-varname
|
@@ -475,4 +481,8 @@ For example:
|
|
475
481
|
[17]: https://img.shields.io/pypi/dm/varname?style=flat-square
|
476
482
|
[19]: https://github.com/alexmojaki/executing#is-it-reliable
|
477
483
|
[20]: https://stackoverflow.com/a/59364138/5088165
|
484
|
+
[21]: https://github.com/lihaoyi/macropy
|
485
|
+
[22]: https://github.com/alexmojaki/birdseye
|
486
|
+
[23]: https://rstudio.github.io/reticulate/
|
487
|
+
[24]: https://docs.python.org/3/library/functions.html#exec
|
478
488
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
varname/__init__.py,sha256=msPiS0pHXpErWWjXSxkVWqjfjLHHX8zcVgWRBwfJlT4,369
|
2
|
+
varname/core.py,sha256=iuipHp0kavT5gR6VEYGDtpOdf23p_aYsll04f7woL0M,19346
|
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=3Z0bEGbrKOWXsfRO5GeJBqqKNOprK-jO2MpVqYwgnIE,23188
|
7
|
+
varname-0.15.0.dist-info/LICENSE,sha256=3bS8O2tMbBPz8rWmZBAOzkHQjcK-b7KwFHyyghEZ-Ak,1063
|
8
|
+
varname-0.15.0.dist-info/METADATA,sha256=Z70KEyKxGrsdqNx83lg-9f8dOgFaMZpgTXtwO9rgp3U,13236
|
9
|
+
varname-0.15.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
10
|
+
varname-0.15.0.dist-info/RECORD,,
|
varname-0.13.5.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
varname/__init__.py,sha256=l5dQ1tAOeicXhv8plZvcnX87u1hLliPL_iYeBNr3ov4,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.5.dist-info/LICENSE,sha256=3bS8O2tMbBPz8rWmZBAOzkHQjcK-b7KwFHyyghEZ-Ak,1063
|
8
|
-
varname-0.13.5.dist-info/METADATA,sha256=OoIZ8sTVPGh4vF9Z0YL_hMXrTqlPvSM7Ec-KUaVB-C0,12845
|
9
|
-
varname-0.13.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
10
|
-
varname-0.13.5.dist-info/RECORD,,
|
File without changes
|