• Error-Msg Jeannie's charming, teasing ways

    From Hen Hanna@21:1/5 to All on Thu Feb 23 14:58:47 2023
    Python's Error-Msg genie (Jeannie) is cute and fickle... She sometimes teases me by not telling me what the VALUE of the "int" is
    ( "That's for me to know, and for you to find out!" ) as in:

    TypeError: can only concatenate str (not "int") to str




    Other times, she (Jeannie) gives me a helpful comment:
    ABCD (above and beyond... her job desc.)


    if (x=0):
    ^^^
    SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?



    Maybe you'd share other EXAMPLES of her charming, teasing ways???



    is there a Tool that can scan my code and tell me such (wink,wink) type suggestions???? ----------- [Maybe you'd like to rewrite this line as ....... ?]
    [Might i interest you in the coding-style wherein ...... ?]
    etc?




    https://stackoverflow.com/questions/26000198/what-does-colon-equal-in-python-mean

    There is new syntax := that assigns values to variables as part of a larger expression. It is affectionately known as “the walrus operator” due to its resemblance to the eyes and tusks of a walrus.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Hen Hanna on Fri Feb 24 14:58:04 2023
    On 23Feb2023 14:58, Hen Hanna <henhanna@gmail.com> wrote:
    Python's Error-Msg genie (Jeannie) is cute and fickle... She
    sometimes teases me by not telling me what the VALUE of the "int" is
    ( "That's for me to know, and for you to find out!" )
    as in:
    TypeError: can only concatenate str (not
    "int") to str

    This is a runtime error< not a syntax error. Valid code using invalid
    values. It can only be seen at runtime.

    Other times, she (Jeannie) gives me a helpful comment:
    ABCD (above and beyond... her job desc.)
    if (x=0):
    ^^^
    SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

    Syntax error can be seen at compile time. Since Python's interpreted,
    the compilation step i usually implicit in trying to run things. But technically this happens before any of _your_ code runs.

    The helpfulness of this warning is a _very_ recent upgrade, with Python
    3.11 I think, maybe 3.10. The syntax errors used to be a lot less
    helpful.

    is there a Tool that can scan my code and tell me such (wink,wink)
    type suggestions????

    There are several type checking programs for Python, with mypy probably
    being the best known. I seem to recall seeing some mention of tools
    which will aid inferring types from partially types programmes, usually
    as an aid to completing the type annotations.

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Cameron Simpson on Thu Feb 23 23:28:04 2023
    On 2/23/2023 10:58 PM, Cameron Simpson wrote:
    On 23Feb2023 14:58, Hen Hanna <henhanna@gmail.com> wrote:
    Python's Error-Msg  genie  (Jeannie)  is cute and fickle...   She
    sometimes teases me by not telling me what the VALUE of the   "int"  is >>                         ( "That's for me to know, and for you to find
    out!" )
    as in:
                              TypeError: can only concatenate str (not
                              "int") to str

    This is a runtime error< not a syntax error. Valid code using invalid
    values. It can only be seen at runtime.

    Other times, she (Jeannie)  gives me a helpful comment:
    ABCD (above and beyond... her job desc.)
                                 if (x=0):
                                       ^^^
    SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

    Syntax error can be seen at compile time. Since Python's interpreted,
    the compilation step i usually implicit in trying to run things. But technically this happens before any of _your_ code runs.

    It *is* a syntax error, and it *is* caught before execution. It's a
    syntax error because the expression following the if (which doesn't need
    the parentheses) must be a boolean expression and "x = 0" is not one of
    those. Python undergoes a compilation of sorts, down to the .pyc file,
    and it catches outright syntax errors in that phase. There are other
    errors that can't be caught until runtime, and they might involve type
    errors (unless one uses some static analysis).

    The helpfulness of this warning is a _very_ recent upgrade, with Python
    3.11 I think, maybe 3.10.  The syntax errors used to be a lot less helpful.

    is there a Tool that can scan my code and tell me   such   (wink,wink) >> type suggestions????

    There are several type checking programs for Python, with mypy probably
    being the best known. I seem to recall seeing some mention of tools
    which will aid inferring types from partially types programmes, usually
    as an aid to completing the type annotations.

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

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