On 2/23/2023 10:58 PM, Cameron Simpson wrote:
On 23Feb2023 14:58, Hen Hanna <henha...@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 <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list