python-varname

Dark magics about variable names in python

MIT License

Downloads
252.1K
Stars
298
Committers
5

Bot releases are hidden (Show)

python-varname - 0.13.1 Latest Release

Published by pwwang 6 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/pwwang/python-varname/compare/0.13.0...0.13.1

python-varname - 0.13.0

Published by pwwang 9 months ago

  • style: change max line length to 88
  • style: clean up test code styles
  • feat: support subscript node for varname (#104)
  • ci: remove python3.8 from CI
  • breaking!: varname of a.b now returns "a.b" instead of "a"

What's Changed

Full Changelog: https://github.com/pwwang/python-varname/compare/0.12.2...0.13.0

python-varname - 0.12.2

Published by pwwang 11 months ago

  • Add helpers.exec_code function to replace exec so that source code is available at runtime
from 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']

What's Changed

Full Changelog: https://github.com/pwwang/python-varname/compare/0.12.1...0.12.2

python-varname - 0.12.1

Published by pwwang 11 months ago

  • Bump executing to 2.0.1

What's Changed

Full Changelog: https://github.com/pwwang/python-varname/compare/0.12.0...0.12.1

python-varname - 0.12.0

Published by pwwang about 1 year ago

  • Support python 3.12
  • Update python3.12 to CI
  • Bump executing to ^2.0
  • Bump up other dependencies
  • Add Dockerfile for codesandbox

Full Changelog: https://github.com/pwwang/python-varname/compare/0.11.2...0.12.0

python-varname - 0.11.2

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

python-varname - 0.11.1

Published by pwwang over 1 year ago

  • ✨ Support starred variable for varname() (#96)
  • ✅ Fix tests
  • 📝 Update docs for varname(strict=...)

Full Changelog: https://github.com/pwwang/python-varname/compare/0.11.0...0.11.1

python-varname -

Published by pwwang over 1 year ago

  • 📝 Update README for shields badges (#91)
  • 🏷️ Overload types for nameof and argname (#77)
  • 💥 Drop python <3.8 for v0.11
    If you need support for python <3.8, please use varname <0.11
python-varname - 0.10.0

Published by pwwang about 2 years ago

  • ✨ Support python 3.11

What's Changed

Full Changelog: https://github.com/pwwang/python-varname/compare/0.9.1...0.10.0

python-varname -

Published by pwwang about 2 years ago

  • ⬆️ Upgrade executing to 1.0
python-varname - 0.9.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
    

What's Changed

Full Changelog: https://github.com/pwwang/python-varname/compare/0.8.3...0.9.0

python-varname -

Published by pwwang over 2 years ago

This is more of a housekeeping release:

  • ⬆️ Upgrade executing to 0.8.3 to make varname work with ipython 8+
  • 📝 Update README.md to add new contributors
  • 🚨 Use flake8 instead of pylint for linting
python-varname -

Published by pwwang over 2 years ago

Fixes

  • 🩹 Use sysconfig instead of distutils.sysconfig to avoid deprecatewarning for python 3.10+ (#71)

Housekeeping

  • 👷 Add python3.10 in CI
  • 📄 Add license back
python-varname -

Published by pwwang about 3 years ago

  • Handle inspect raises "could not get source code" when printing rich exception message
python-varname -

Published by pwwang about 3 years ago

Compared to v0.7.3

  • Add UsingExecWarning when exec is used to retrieve func for argname().
  • Remove NonVariableArgumentError. Use ImproperUseError instead.
  • Add VarnameError and VarnameWarning as root for varname-related exceptions and warnings, respectively.
  • Default strict to True for varname(), helpers.register() and helpers.Wrapper()
  • Limit number of context lines for showing where ImproperUseError happens

Compared to v0.7.0

  • Add UsingExecWarning when exec is used to retrieve func for argname().
  • Remove NonVariableArgumentError. Use ImproperUseError instead.
  • Add VarnameError and VarnameWarning as root for varname-related exceptions and warnings, respectively.
  • Add strict mode to varname(), helpers.register() and helpers.Wrapper() (#57)
  • Support the walrus operator (:=) (#58)
  • Change argname() to accept argument names instead of arguments themselves
  • Remove pos_only argument from argname()
  • Add ignore argument to argname() to ignore intermediate frames
  • Limit VarnameRetrievingError to the situations only when the AST node is not able to be retrieved.
python-varname -

Published by pwwang about 3 years ago

  • Indicate where the ImproperUseError happens for varname() (#60)
  • Add VarnameException and VarnameWarning as root for all varname-defined exceptions and warnings.
python-varname -

Published by pwwang about 3 years ago

  • Add strict mode to varname() (#57)

    def func():
      return varname(strict=True)
    
    a = func() # 'a'
    a = [func()] # ImproperUseError
    
  • Support the walrus operator (:=) (#58)

    a = (b := func())
    # a == b == 'b'
    

Credits:

  • @breuleux
python-varname -

Published by pwwang over 3 years ago

  • Add ignore argument to argname2()
  • Fix Fix utils.get_argument_sources() when kwargs is given as **kwargs.
python-varname -

Published by pwwang over 3 years ago

  • ImproperUseError is now independent of VarnameRetrievingError (#49)
  • Deprecate argname, superseded by argname2
    >>> argname(a, b, ...) # before
    >>> argname2('a', 'b', ...) # after
    
  • Add dispatch argument to argname/argment2 to be used for single-dispatched functions (#53).
python-varname -

Published by pwwang over 3 years ago

  • Add sep argument to helpers.debug()