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 '='?
is there a Tool that can scan my code and tell me such (wink,wink)
type suggestions????
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>
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:31:36 |
Calls: | 10,389 |
Files: | 14,061 |
Messages: | 6,416,956 |