Sujet : Re: Collecting unassigned Expressions
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 26. Aug 2023, 00:31:06
Autres entêtes
Organisation : Stefan Ram
Message-ID : <message-20230826002855@ram.dialup.fu-berlin.de>
References : 1
Guenther Sohler <
guenther.sohler@gmail.com> writes:
I am wondering If an embedded Python Interpreter can detect unassigned
Expressions. Cases where functions Return values but they are Not
assignwd. E.g.
Calc_square(4)
Or
3*4-myval()
1. If "Calc_square(4)" appears in the context "n=Calc_square(4)",
then its value is assigned. So, it is not necessarily an example
of a function call expression the value of which is not assigned.
2. In Python function call expressions always have a value.
3. If you can modify the the interpreter, you surely can make it
emit an expression such as "Info: The value of the function call
expression 'Calc_square(4)' was not bound to an identifier.".
4. You also can use the parser library that comes with Python to
parse source code and detect such situations yourself. E.g.,
import ast
...
parse = ast.parse( source, filename )
for entry in ast.walk( parse ):
...
.