• Collecting unassigned Expressions

    From Guenther Sohler@21:1/5 to All on Thu Aug 24 13:23:26 2023
    Hi

    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()

    Thank you for your hints

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Guenther Sohler on Fri Aug 25 23:31:06 2023
    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 ):
    ...

    .

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)