Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Real Users never know what they want, but they always know when your program doesn't deliver it.


devel / comp.lang.python / Re: How to find the full class name for a frame

SubjectAuthor
o Re: How to find the full class name for a framedn

1
Re: How to find the full class name for a frame

<mailman.203.1691126063.23016.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28257&group=comp.lang.python#28257

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: How to find the full class name for a frame
Date: Fri, 4 Aug 2023 17:14:04 +1200
Organization: DWM
Lines: 68
Message-ID: <mailman.203.1691126063.23016.python-list@python.org>
References: <CANy1k1iLXzxGd2MHwKs_9-i99RUTgmkTdUHX5mYTj=Wsx+RQqA@mail.gmail.com>
<78264357-9277-1394-4239-0ecca17834e1@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de ynpe1vlwtxW6zZgibwxTnQFt27lfZkA6TXbqMwb7WOow==
Cancel-Lock: sha1:0VBkt/um2iIHxqa5zIlXCHpokX4= sha256:CkflOusVM2grn4KnUMPWHmtDTT10wUcQ/QYsr52sMmw=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=CM3RIOHe; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04;
'subject:name': 0.07; '"""': 0.09; '=dn': 0.09; 'deeper': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'prints': 0.09; 'received:192.168.1.64': 0.09;
'subject:class': 0.09; 'url:reference': 0.09; 'import': 0.15;
'(without': 0.16; 'arguments': 0.16; 'executed': 0.16; 'frames':
0.16; 'given,': 0.16; 'hint': 0.16; 'inspect': 0.16; 'integer':
0.16; 'message-id:@DancesWithMice.info': 0.16; 'namely': 0.16;
'received:51.254': 0.16; 'received:51.254.211': 0.16;
'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'stack.': 0.16; 'typing': 0.16;
'want,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'calls': 0.19;
'to:addr:python-list': 0.20; 'purposes': 0.22; 'skip:_ 10': 0.22;
'code': 0.23; 'subject:How': 0.23; 'idea': 0.24; 'library': 0.26;
'object': 0.26; 'function': 0.27; 'sense': 0.28; 'header:User-
Agent:1': 0.30; 'default': 0.31; 'header:Organization:1': 0.31;
"doesn't": 0.32; 'question': 0.32; 'concept': 0.32; 'execution':
0.32; 'objects': 0.32; 'python-list': 0.32; 'returning': 0.32;
'unknown': 0.32; 'received:192.168.1': 0.32; 'subject:for': 0.33;
"didn't": 0.34; 'header:In-Reply-To:1': 0.34; 'question.': 0.35;
'really': 0.37; "it's": 0.37; 'received:192.168': 0.37; 'put':
0.38; 'neither': 0.39; 'should': 0.40; 'method': 0.61; 'above':
0.62; 'skip:i 20': 0.62; 'internal': 0.63; 'pass': 0.64;
'received:51': 0.64; 'specialized': 0.64; 'top': 0.65; 'only.':
0.69; 'below': 0.69; 'interesting': 0.71; 'signature': 0.76;
'depth': 0.81; 'stack,': 0.84
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud ECCCC4874
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1691126054;
bh=x1hfrJ5GdEwvtXFHHgNhHEal9+nnyo97x2t/GDnVMRA=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=CM3RIOHeHtOQmqIgI5UgDihoVmDRlQU7m5Bs8eHvWQ+519Zow+/AM6w12q/Wv0lhc
OXXP0wQhwGnZpGWqm2JP8KOGC5VTuWWzfu0m2kl/CnpTvPQGrr+JRfHychGMFCQ6qE
x9+h0UF6zyd2hJ4HXAdi6r6jWM29vA7TPrgoHF0YObSydzROJ4hjCmrXFidfPNKGpZ
htQuWWRRSZnrZPXKRBOFk78UllCjHCKpjl3g/VytE1Ypu6veoHzFh3omJKYEzLK/HI
OTEVRy4skeAR2dRfCtyHg+2J86CIB+lCnjM75H4kOpB4zTbkoEg7z/MXxV27YK4ZQW
3CIXRDnwzjjOA==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Content-Language: en-GB
In-Reply-To: <CANy1k1iLXzxGd2MHwKs_9-i99RUTgmkTdUHX5mYTj=Wsx+RQqA@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <78264357-9277-1394-4239-0ecca17834e1@DancesWithMice.info>
X-Mailman-Original-References: <CANy1k1iLXzxGd2MHwKs_9-i99RUTgmkTdUHX5mYTj=Wsx+RQqA@mail.gmail.com>
 by: dn - Fri, 4 Aug 2023 05:14 UTC

On 04/08/2023 15.34, Jason Friedman via Python-list wrote:
> import inspect
>
> def my_example(arg1, arg2):
> print(inspect.stack()[0][3])
> my_frame = inspect.currentframe()
> args,_,_,values = inspect.getargvalues(my_frame)
> args_rendered = [f"{x}: {values[x]}" for x in args]
> print(args_rendered)
>
> my_example("a", 1)
>
>
> The above "works" in the sense it prints what I want, namely the method
> name (my_example) and the arguments it was called with.

The above didn't 'work' - please copy-paste and ensure that the
email-client is respecting indentation.

> My question is: let's say I wanted to add a type hint for my_frame.
>
> my_frame: some_class_name = inspect.currentframe()
>
> What would I put for some_class_name?
> "frame" (without quotations) is not recognized,
> Nor is inspect.frame.

We know Python code is executed in an execution frame.
(https://docs.python.org/3/reference/executionmodel.html?highlight=frame)

We are told "Frame objects Frame objects represent execution frames."
(https://docs.python.org/3/reference/datamodel.html?highlight=frame).
The word "represent" conflicts with the idea of "are".

'Under the hood' inspect calls sys._current_frames()
(https://docs.python.org/3/library/sys.html?highlight=frame). That code is:

def _getframe(*args, **kwargs): # real signature unknown
"""
Return a frame object from the call stack.

If optional integer depth is given, return the frame object that many
calls below the top of the stack. If that is deeper than the call
stack, ValueError is raised. The default for depth is zero, returning
the frame at the top of the call stack.

This function should be used for internal and specialized purposes
only.
"""
pass

Which rather suggests that if the sys library doesn't know the
signature, then neither typing nor we mere-mortals are going to do so,
either.

Theory: the concept of a frame does not really exist at the Python-level
(remember "represents"). Frames (must) exist at the C-level
(https://docs.python.org/3/c-api/frame.html?highlight=frame#c.PyFrameObject)
of the virtual-machine - where typing is not a 'thing'.

It's an interesting question. Perhaps a better mind than mine can give a
better answer?
--
Regards,
=dn


devel / comp.lang.python / Re: How to find the full class name for a frame

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor