@@ -202,7 +202,7 @@ def will(frame: int = 1, raise_exc: bool = True) -> str:
202202
203203
204204def nameof (
205- var , # pylint: disable=unused-argument
205+ var , # pylint: disable=unused-argument
206206 * more_vars ,
207207 # *, keyword only argument, supported with python3.8+
208208 frame : int = 1 ,
@@ -294,10 +294,10 @@ def nameof(
294294 out = argname2 (
295295 "var" , "*more_vars" , func = nameof , frame = frame , vars_only = vars_only
296296 )
297- return out if more_vars else out [0 ] # type: ignore
297+ return out if more_vars else out [0 ] # type: ignore
298298
299299
300- def argname ( # pylint: disable=unused-argument,too-many-branches
300+ def argname ( # pylint: disable=unused-argument,too-many-branches
301301 arg : Any ,
302302 * more_args : Any ,
303303 # *, keyword-only argument, only available with python3.8+
@@ -393,7 +393,7 @@ def argname( # pylint: disable=unused-argument,too-many-branches
393393 pos_only = pos_only ,
394394 )
395395
396- ret = [] # type: List[ArgSourceType]
396+ ret = [] # type: List[ArgSourceType]
397397 for argnode in argname_node .args :
398398 if not isinstance (argnode , (ast .Name , ast .Subscript , ast .Starred )):
399399 raise ValueError (
@@ -412,7 +412,7 @@ def argname( # pylint: disable=unused-argument,too-many-branches
412412 raise ValueError (
413413 f"No such variable positional argument { posvar !r} "
414414 )
415- ret .extend (argument_sources [argnode .value .id ]) # type: ignore
415+ ret .extend (argument_sources [argnode .value .id ]) # type: ignore
416416
417417 elif isinstance (argnode , ast .Name ):
418418 if argnode .id not in argument_sources :
@@ -441,7 +441,7 @@ def argname( # pylint: disable=unused-argument,too-many-branches
441441 f"{ name !r} is not a keyword argument "
442442 "(**kwargs, for example)."
443443 )
444- ret .append (argument_sources [name ][subscript ]) # type: ignore
444+ ret .append (argument_sources [name ][subscript ]) # type: ignore
445445
446446 if vars_only :
447447 for source in ret :
@@ -451,7 +451,7 @@ def argname( # pylint: disable=unused-argument,too-many-branches
451451 "or an attribute."
452452 )
453453
454- return ret [0 ] if not more_args else tuple (ret ) # type: ignore
454+ return ret [0 ] if not more_args else tuple (ret ) # type: ignore
455455
456456
457457def argname2 (
@@ -461,6 +461,7 @@ def argname2(
461461 func : Callable = None ,
462462 dispatch : Type = None ,
463463 frame : int = 1 ,
464+ ignore : IgnoreType = None ,
464465 vars_only : bool = True ,
465466) -> ArgSourceType :
466467 """Get the names/sources of arguments passed to a function.
@@ -505,14 +506,19 @@ def argname2(
505506 specified, expect `func` to be the generic function if provided.
506507 frame: The frame where target function is called from this call.
507508 Calls from python standard libraries are ignored.
509+ ignore: The intermediate calls to be ignored. See `varname.ignore`
508510 vars_only: Require the arguments to be variables only.
509511 If False, `asttokens` is required to retrieve the source.
510512
511513 Returns:
512514 Scalar string if
513515
514516 """
515- ignore_list = IgnoreList .create (ignore_lambda = False , ignore_varname = False )
517+ ignore_list = IgnoreList .create (
518+ ignore ,
519+ ignore_lambda = False ,
520+ ignore_varname = False ,
521+ )
516522 # where func(...) is called, skip the argname2() call
517523 func_frame = ignore_list .get_frame (frame + 1 )
518524 func_node = get_node_by_frame (func_frame )
@@ -545,17 +551,17 @@ def argname2(
545551 vars_only = vars_only ,
546552 pos_only = False ,
547553 )
548- except TypeError as terr :
554+ except Exception as err :
549555 raise VarnameRetrievingError (
550556 "Have you specified the right `frame`?"
551- ) from terr
557+ ) from err
552558
553- out = [] # type: List[ArgSourceType]
559+ out = [] # type: List[ArgSourceType]
554560 farg_star = False
555561 for farg in (arg , * more_args ):
556562
557563 farg_name = farg
558- farg_subscript = None # type: str | int
564+ farg_subscript = None # type: str | int
559565 match = re .match (r"^([\w_]+)\[(.+)\]$" , farg )
560566 if match :
561567 farg_name = match .group (1 )
@@ -582,7 +588,7 @@ def argname2(
582588 )
583589
584590 if farg_subscript is not None :
585- out .append (source [farg_subscript ]) # type: ignore
591+ out .append (source [farg_subscript ]) # type: ignore
586592 elif farg_star :
587593 out .extend (source )
588594 else :
@@ -591,5 +597,5 @@ def argname2(
591597 return (
592598 out [0 ]
593599 if not more_args and not farg_star
594- else tuple (out ) # type: ignore
600+ else tuple (out ) # type: ignore
595601 )
0 commit comments