MCPcopy Create free account
hub / github.com/celery/celery / _getfullargspec

Function _getfullargspec

celery/utils/functional.py:365–406  ·  view source on GitHub ↗
(fun)

Source from the content-addressed store, hash-verified

363 import annotationlib as _annotationlib
364
365 def _getfullargspec(fun):
366 # In Python 3.14+, inspect.getfullargspec evaluates annotations by default
367 # (PEP 649), raising NameError for TYPE_CHECKING-only types. We don't need
368 # annotations here, so use Format.STRING to avoid evaluation.
369 # For bound methods, use __func__ so that 'self' is included in args,
370 # matching the behaviour of getfullargspec on older Python versions.
371 # Pass follow_wrapped=False to match inspect.getfullargspec's behaviour
372 # of introspecting the callable itself rather than following __wrapped__;
373 # this matters for tasks defined via functools.wraps over a variadic
374 # wrapper (e.g. dependency-injection decorators) where the wrapper's
375 # signature -- not the inner function's -- is what should be validated
376 # against caller-supplied args.
377 target = getattr(fun, '__func__', fun)
378 sig = inspect.signature(
379 target,
380 follow_wrapped=False,
381 annotation_format=_annotationlib.Format.STRING,
382 )
383 args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults = [], None, None, [], [], {}
384 for name, param in sig.parameters.items():
385 kind = param.kind
386 if kind in (param.POSITIONAL_ONLY, param.POSITIONAL_OR_KEYWORD):
387 args.append(name)
388 if param.default is not param.empty:
389 defaults.append(param.default)
390 elif kind == param.VAR_POSITIONAL:
391 varargs = name
392 elif kind == param.KEYWORD_ONLY:
393 kwonlyargs.append(name)
394 if param.default is not param.empty:
395 kwonlydefaults[name] = param.default
396 elif kind == param.VAR_KEYWORD:
397 varkw = name
398 return inspect.FullArgSpec(
399 args=args,
400 varargs=varargs,
401 varkw=varkw,
402 defaults=tuple(defaults) or None,
403 kwonlyargs=kwonlyargs,
404 kwonlydefaults=kwonlydefaults or None,
405 annotations={},
406 )
407else:
408 _getfullargspec = inspect.getfullargspec
409

Callers 1

head_from_funFunction · 0.85

Calls 2

signatureMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected