[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread Guido van Rossum
Is it not acceptable to create new functions that return non-named-tuple objects (e.g. dataclasses with slots)? Otherwise the way the stats result tuple works is a reasonable approach (and possibly deprecate indexed access?) On Sun, Apr 17, 2022 at 10:23 AM Pablo Galindo Salgado wrote: > Hi, >

[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread MRAB
On 2022-04-18 01:23, Steven D'Aprano wrote: On Sun, Apr 17, 2022 at 08:35:06PM +0100, MRAB wrote: You could return only the current attributes by default, but the extra attributes on demand. (Slightly strange, but backwards-compatible.) Slicing could also return what was requested, e.g. t[ :

[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread Steven D'Aprano
On Sun, Apr 17, 2022 at 06:20:53PM +0100, Pablo Galindo Salgado wrote: > These APIs are inspect.getframeinfo, inspect.getouterframes, > inspect.getinnerframes, inspect.stack and inspect.trace. Are you referring to the FrameInfo namedtuple rather than the functions themselves? inspect.stack()

[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread Steven D'Aprano
On Sun, Apr 17, 2022 at 08:35:06PM +0100, MRAB wrote: > You could return only the current attributes by default, but the extra > attributes on demand. (Slightly strange, but backwards-compatible.) > Slicing could also return what was requested, e.g. t[ : 4] would return > the first 4, t[ : 5]

[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread Eric V. Smith
Things like os.stat_result use PyStructSequence_NewType, which is the C equivalent of a namedtuple. But a Struct Sequence has the extension of being able to have more named fields than the tuple length. It was designed, so I understand, just for cases like this. I don't know if it would be

[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread Pablo Galindo Salgado
That's an interesting idea but the objective is not to only produce a backwards compatible version but also a maintainable solution that also doesn't have weird side effects or strange behaviour. I find things that behaves like that a bit surprising. But this is something we could certainly do.

[Python-Dev] Re: Updating inspect APIs

2022-04-17 Thread MRAB
On 2022-04-17 18:20, Pablo Galindo Salgado wrote: Hi, We are currently debating in gh-88116 (https://github.com/python/cpython/issues/88116 ) what's the best way forward to update the APIs in the inspect module to include the new position

[Python-Dev] Updating inspect APIs

2022-04-17 Thread Pablo Galindo Salgado
Hi, We are currently debating in gh-88116 ( https://github.com/python/cpython/issues/88116) what's the best way forward to update the APIs in the inspect module to include the new position information. These APIs are inspect.getframeinfo, inspect.getouterframes, inspect.getinnerframes,