Dynamic typing
Dynamic typing
Posted Aug 9, 2019 14:22 UTC (Fri) by rahulsundaram (subscriber, #21946)In reply to: Dynamic typing by jem
Parent article: Knoll: Technical vision for Qt 6
Use Type Hints (c.f. https://docs.python.org/3/library/typing.html) and enforce it at commit time.
Posted Aug 10, 2019 9:48 UTC (Sat)
by swilmet (subscriber, #98424)
[Link] (4 responses)
Also, when there is a typo in a variable or function name, the error can be discovered only at runtime AFAIK. When doing big refactorings in a sizeable codebase, having a good compiler is of great help.
Posted Aug 10, 2019 12:11 UTC (Sat)
by rahulsundaram (subscriber, #21946)
[Link] (3 responses)
#!/usr/bin/python3
is_this_true: bool = True
is_this_true: bool = 'explain_this'
$mypy quicktest.py
Posted Aug 10, 2019 12:23 UTC (Sat)
by rahulsundaram (subscriber, #21946)
[Link]
Use something like https://github.com/nvie/vim-flake8 and have some tests built-in. Not perfect but certainly not too hard to stop the easy mistakes
Posted Aug 14, 2019 13:47 UTC (Wed)
by swilmet (subscriber, #98424)
[Link] (1 responses)
Unfortunately there are lots of Python codebases out there without type hints.
Posted Aug 14, 2019 14:02 UTC (Wed)
by rahulsundaram (subscriber, #21946)
[Link]
Indeed, keep in mind this is fairly recent: Python 3.6
> Unfortunately there are lots of Python codebases out there without type hints.
This is slowly changing, if you care about a codebase either submit a PR or have stub files in parallel that adds such support if upstream is not convinced of them yet along the lines of https://github.com/python/typeshed
Dynamic typing
Dynamic typing
quicktest.py:5: error: Incompatible types in assignment (expression has type "str", variable has type "bool")
Dynamic typing
Dynamic typing
Dynamic typing
