Skip to content

Releases: pwwang/python-varname

0.8.0 (#63)

13 Aug 18:36
059f7f7
Compare
Choose a tag to compare

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.

0.7.3

10 Aug 23:01
67ee70f
Compare
Choose a tag to compare
  • Indicate where the ImproperUseError happens for varname() (#60)
  • Add VarnameException and VarnameWarning as root for all varname-defined exceptions and warnings.

0.7.2 (#59)

10 Aug 07:39
d3182fd
Compare
Choose a tag to compare
  • 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:

0.7.1: Add `ignore` argument to `argname2()` (#55)

07 Jul 07:06
867e4ae
Compare
Choose a tag to compare
  • Add ignore argument to argname2()
  • Fix Fix utils.get_argument_sources() when kwargs is given as **kwargs.

0.7.0 (#54)

06 Jul 21:31
a39f4c9
Compare
Choose a tag to compare
  • 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).

0.6.5 (#52)

21 Jun 23:28
81a1373
Compare
Choose a tag to compare
  • Add sep argument to helpers.debug()

0.6.4 (#50)

28 Apr 22:13
218cbf0
Compare
Choose a tag to compare
  • Add ImproperUseError to distinguish node retrieving error from improper varname use #49

0.6.3

01 Mar 21:34
c31b9b5
Compare
Choose a tag to compare
  • Fix standard library ignoring ignores 3rd-party libraries under site-packages/
  • Allow pathlib.Path object to be used in ignore items

0.6.2: Using argname to reimplement nameof (#44)

02 Feb 19:53
e63db96
Compare
Choose a tag to compare
  • Remove argument full for nameof, use vars_only instead. When vars_only=False, source of the argument returned.
    # before:
    nameof(a.b, full=True) # 'a.b'
    nameof(x[0], full=True) # unable to fetch
    # after (requires asttoken):
    nameof(a.b, vars_only=False) # 'a.b'
    nameof(x[0], vars_only=False) # 'x[0]'
  • Add argument frame to argname, so that it can be wrapped.
    def argname2(arg, *more_args):
        return argname(arg, *more_args, frame=2)
  • Allow argname to fetch the source of variable keyword arguments (**kwargs), which will be an empty dict ({}) when no keyword arguments passed.
    def func(a, **kwargs):
        return argname(a, kwargs)
    # before:
    func(x) # raises error
    # after:
    func(x) # returns ('x', {})
  • Add argument pos_only to argname to only match the positional arguments
    # before
    def func(a, b=1):
      return argname(a)
    func(x) # 'x'
    func(x, b=2) # error since 2 is not ast.Name
    
    # after
    def func(a, b=1):
      return argname(a, pos_only=True)
    func(x) # 'x'
    func(x, b=2) # 'x'
  • Parse the arguments only if needed
    # before
    def func(a, b):
      return argname(a)
    func(x, 1) # NonVariableArgumentError
    
    # after
    func(x, 1) # 'x'
  • Allow variable positional arguments for argname so that argname(*args) is allowed
    # before
    def func(arg, *args):
      return argname(arg, args) # *args not allowed
    x = y = 1
    func(x, y) # ('x', ('y', 1))
    
    # after
    def func(arg, *args):
      return argname(arg, *args)
    x = y = 1
    func(x, y) # ('x', 'y')
  • Add vars_only (defaults to False) argument to helpers.debug so source of expression becomes available
    a=1
    debug(a+a) # DEBUG: a+a=2

0.6.1

29 Jan 07:17
bfad7f6
Compare
Choose a tag to compare
  • Add argname to retrieve argument names/sources passed to a function