Hello,

a couple of remarks before replying to your question :

1/ This list is dedicated to Pylons and Pyramid, so a general question
about the Python standard library is off-topic
2/ You could have googled "inspect formatargspec" and found answers
3/ You could have read the documentation of the standard library

The documentation of "inspect" for Python 3.10
(https://docs.python.org/3.10/library/inspect.html) states :

"Deprecated since version 3.5: Use signature() and Signature Object,
which provide a better introspecting API for callables."

And indeed, if you switch to the Python 3.11 / 3.12 versions of the
docs, you'll find that the function has been removed. You certainly
had a deprecation warning in Python 3.9/3.10, which you ignored

My $0.02,

Laurent.


Le mar. 14 nov. 2023 à 19:17, Oberdan Santos <sc.ober...@gmail.com> a écrit :
>
> Hello!!
> When trying to run my code I am receiving an error.
>
> import inspect
> import sys
>
> try:
>     import importlib.metadata as importlib_metadata  # noqa F401
> except ImportError:  # pragma: no cover
>     # bw-compat shim for py37
>     import importlib_metadata  # noqa F401
>
>
> def fix_type_error(exc_info, callable, varargs, kwargs):
>     """
>     Given an exception, this will test if the exception was due to a
>     signature error, and annotate the error with better information if
>     so.
>
>     Usage::
>
>       try:
>           val = callable(*args, **kw)
>       except TypeError:
>           exc_info = fix_type_error(None, callable, args, kw)
>           raise exc_info[0], exc_info[1], exc_info[2]
>     """
>     if exc_info is None:
>         exc_info = sys.exc_info()
>     if (
>         exc_info[0] != TypeError
>         or str(exc_info[1]).find('arguments') == -1
>         or getattr(exc_info[1], '_type_error_fixed', False)
>     ):
>         return exc_info
>     exc_info[1]._type_error_fixed = True
>     argspec = inspect.formatargspec(*inspect.getargspec(callable))
>     args = ', '.join(map(_short_repr, varargs))
>     if kwargs and args:
>         args += ', '
>     if kwargs:
>         kwargs = sorted(kwargs.items())
>         args += ', '.join(['%s=...' % n for n, v in kwargs])
>     gotspec = '(%s)' % args
>     msg = f'{exc_info[1]}; got {gotspec}, wanted {argspec}'
>     exc_info[1].args = (msg,)
>     return exc_info
>
>
>
> ERRO:
> AttributeError: module 'inspect' has no attribute 'formatargspec'.
> Did you mean: 'formatargvalues'?
>
>
> I've tried some changes to the code line, but to no avail.
> argspec = inspect.formatargspec(*inspect.getargspec(callable))
> Every help is welcome
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to pylons-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pylons-discuss/cab4b239-75df-44ba-9d39-4fea371e2b6dn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAB7cU6zgRfxSEvNAG8h%3DVHjciggq9adxoUeucOvM7HnYcmrKBA%40mail.gmail.com.

Reply via email to