Python talk Wed: Guido: Optional Static Typing for Python

Gary E. Miller gem at rellim.com
Fri Jun 8 23:25:28 UTC 2018


Yo Hal!

On Thu, 07 Jun 2018 21:33:56 -0700
Hal Murray via devel <devel at ntpsec.org> wrote:

> I really like type checking.  I remember the
> first time I figured out what was going on when the compiler gave me
> an error message for using foo where I wanted foo*.  Thank you!

You motivated me to install mypy, and run it on two NTPsec Python
files.  We can charaterize this as a 'target rich environment':

ntpsec # mypy ntpclients/ntpviz.py 
/usr/local/lib64/python2.7/site-packages/ntp/util.py:16: error: Cannot find module named 'ntp.ntpc'
/usr/local/lib64/python2.7/site-packages/ntp/util.py:16: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
/usr/local/lib64/python2.7/site-packages/ntp/util.py:1394: error: Incompatible import of "OrderedDict" (imported name has type "Type[OrderedDict[Any, Any]]", local name has type "Type[OrderedDict]")
/usr/local/lib64/python2.7/site-packages/ntp/util.py:1396: error: Name 'OrderedDict' already defined (possibly by an import)
/usr/local/lib64/python2.7/site-packages/ntp/statfiles.py:25: error: Need type annotation for 'peermap'
ntpclients/ntpviz.py:199: error: Need type annotation for 'percs'
ntpclients/ntpviz.py:1276: error: String interpolation mixes specifier with and without mapping keys
ntpclients/ntpviz.py:1546: error: No library stub file for module 'psutil'
ntpclients/ntpviz.py:1546: note: (Stub files are from https://github.com/python/typeshed)
ntpclients/ntpviz.py:1670: error: Incompatible types in assignment (expression has type "str", variable has type "datetime")
ntpclients/ntpviz.py:1713: error: Argument 1 to "utcfromtimestamp" of "datetime" has incompatible type "None"; expected "float"
ntpclients/ntpviz.py:1715: error: Argument 1 to "utcfromtimestamp" of "datetime" has incompatible type "None"; expected "float"
ntpclients/ntpviz.py:1722: error: Argument 1 to "float" has incompatible type "None"; expected "Union[SupportsFloat, str, bytes]"
ntpclients/ntpviz.py:1888: error: Incompatible types in assignment (expression has type "List[<nothing>]", variable has type "NTPViz")
ntpclients/ntpviz.py:1894: error: "NTPViz" has no attribute "append"
ntpclients/ntpviz.py:1916: error: "NTPViz" has no attribute "__iter__" (not iterable)

ntpsec # mypy pylib/packet.py 
/usr/local/lib64/python2.7/site-packages/ntp/util.py:16: error: Cannot find module named 'ntp.ntpc'
/usr/local/lib64/python2.7/site-packages/ntp/util.py:1394: error: Incompatible import of "OrderedDict" (imported name has type "Type[OrderedDict[Any, Any]]", local name has type "Type[OrderedDict]")
/usr/local/lib64/python2.7/site-packages/ntp/util.py:1396: error: Name 'OrderedDict' already defined (possibly by an import)
pylib/packet.py:196: error: Cannot find module named 'ntp.ntpc'
pylib/packet.py:196: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
pylib/packet.py:229: error: Name 'raw_input' is not defined
pylib/packet.py:241: error: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "Type[str]")
pylib/packet.py:249: error: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "Type[bytes]")
pylib/packet.py:264: error: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "Type[str]")
pylib/packet.py:1595: error: Assignment to variable 'e' outside except: block

Not sure what that all means, much of it is junk, but a couple of eye openers
in there.

Time to add a waf mypy target.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
	gem at rellim.com  Tel:+1 541 382 8588

	    Veritas liberabit vos. -- Quid est veritas?
    "If you can’t measure it, you can’t improve it." - Lord Kelvin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ntpsec.org/pipermail/devel/attachments/20180608/1447fb64/attachment.bin>


More information about the devel mailing list