Dark magics about variable names in python
MIT License
Bot releases are hidden (Show)
Full Changelog: https://github.com/pwwang/python-varname/compare/0.13.0...0.13.1
Published by pwwang 9 months ago
varname
of a.b
now returns "a.b"
instead of "a"
Full Changelog: https://github.com/pwwang/python-varname/compare/0.12.2...0.13.0
Published by pwwang 11 months ago
helpers.exec_code
function to replace exec
so that source code is available at runtimefrom varname import argname
from varname.helpers import exec_code
class Obj:
def __init__(self):
self.argnames = []
def receive(self, arg):
self.argnames.append(argname('arg', func=self.receive))
obj = Obj()
# exec('obj.receive(1)') # Error
exec_code('obj.receive(1)')
exec_code('obj.receive(2)')
print(obj.argnames) # ['1', '2']
Full Changelog: https://github.com/pwwang/python-varname/compare/0.12.1...0.12.2
Published by pwwang 11 months ago
Full Changelog: https://github.com/pwwang/python-varname/compare/0.12.0...0.12.1
Published by pwwang about 1 year ago
executing
to ^2.0
Full Changelog: https://github.com/pwwang/python-varname/compare/0.11.2...0.12.0
Published by pwwang over 1 year ago
✨ Add jsobj
to create dict without explicitly specifying the key-value pairs
from varname.helpers import jsobj
a = 1
b = 2
# before
dict(a=a, b=b, c=3) # {'a': 1, 'b': 2, 'c': 3}
# after
jsobj(a, b, c=3) # {'a': 1, 'b': 2, 'c': 3}
Full Changelog: https://github.com/pwwang/python-varname/compare/0.11.1...0.11.2
Published by pwwang over 1 year ago
varname(strict=...)
Full Changelog: https://github.com/pwwang/python-varname/compare/0.11.0...0.11.1
Published by pwwang about 2 years ago
Full Changelog: https://github.com/pwwang/python-varname/compare/0.9.1...0.10.0
Published by pwwang about 2 years ago
⬆️ Upgrade executing to 0.9
🗑️ Remove deprecated argname2
✨ Support constants for argname
even when vars_only=True
✨ Support __getattr__/__setattr__
etc for argname
Now you can do:
from varname import argname
class Foo:
def __getattr__(self, name):
"""Similar for `__getitem__`"""
print(argname("name"))
def __setattr__(self, name, value):
"""Similar for `__setitem__`"""
print(argname("name"))
print(argname("value"))
def __add__(self, other):
"""Similar for `__sub__`, `__mul__`, `__truediv__`, `__floordiv__`,
`__mod__`, `__pow__`, `__lshift__`, `__rshift__`, `__matmul__`,
`__and__`, `__xor__`, `__or__`
"""
print(argname("other"))
def __eq__(self, other):
"""Similar for `__lt__`, `__le__`, `__gt__`, `__ge__`, `__ne__`
"""
print(argname("other"))
foo = Foo()
b = 1
foo.x # prints: 'x' (note the quotes)
foo.x = b # prints: 'x' and b
foo + b # prints: b
foo == b # prints: b
Full Changelog: https://github.com/pwwang/python-varname/compare/0.8.3...0.9.0
Compared to v0.7.3
UsingExecWarning
when exec
is used to retrieve func
for argname()
.NonVariableArgumentError
. Use ImproperUseError
instead.VarnameError
and VarnameWarning
as root for varname-related exceptions and warnings, respectively.strict
to True
for varname()
, helpers.register()
and helpers.Wrapper()
ImproperUseError
happensCompared to v0.7.0
UsingExecWarning
when exec
is used to retrieve func
for argname()
.NonVariableArgumentError
. Use ImproperUseError
instead.VarnameError
and VarnameWarning
as root for varname-related exceptions and warnings, respectively.strict
mode to varname()
, helpers.register()
and helpers.Wrapper()
(#57):=
) (#58)argname()
to accept argument names instead of arguments themselvespos_only
argument from argname()
ignore
argument to argname()
to ignore intermediate framesVarnameRetrievingError
to the situations only when the AST node is not able to be retrieved.>>> argname(a, b, ...) # before
>>> argname2('a', 'b', ...) # after