Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'static': 0.04; 'argument': 0.05; 'falls': 0.09; 'yeah,': 0.09; 'contagious.': 0.16; 'finite': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'infinity': 0.16; 'infinity,': 0.16; 'integer.': 0.16; 'iterator,': 0.16; 'iterators': 0.16; 'looping': 0.16; 'reedy': 0.16; 'terminate.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'passing': 0.19; 'aug': 0.22; 'issue.': 0.22; "aren't": 0.24; 'certainly': 0.24; 'visible': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'implicit': 0.31; 'languages': 0.32; 'quite': 0.32; 'checking': 0.33; "i'd": 0.34; 'something': 0.35; 'operations': 0.35; 'usual': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'yield': 0.36; 'subject:?': 0.36; 'positive': 0.37; 'to:addr :python-list': 0.38; 'issue': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'is.': 0.60; 'guarantee': 0.63; 'skip:n 10': 0.64; 'float,': 0.84; 'careful': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=n/Rh/EpqIIEz2fd/nMAXznIPMZxOntL7yCZeyiU+QJc=; b=X+TjYYOKnX0wsDnPHG4YXbhAF9hZ22Ec79rPYGig05dFA/5ybInBA0qqHCUn3GESkN ULO7Tsmu9br59YW5+siVne+Dm6qU4/0M95ac74znXrHBG/hN5zXoX+L+O3e6zVqEKA9K pAZHwzKzbYojLDRfC3E5NfQ6SlCz+esEpjKsuIoUABgkB/YwH5V1AIObWpC9a0fvqZ8w Wl0Uc7mqMXSF4MQeTJUGsrHU334LI7fGHdHDR2w7tyepatBNevd/v1a4Sz7i3SAlV5L/ vwgehbrFvfBGAeRpf4wOO2uLMkT/niwp2jdgm/wmB9gsss5uNbLieiCS12YmYfwsyArY T+gg== MIME-Version: 1.0 X-Received: by 10.52.89.170 with SMTP id bp10mr154157vdb.104.1375834599724; Tue, 06 Aug 2013 17:16:39 -0700 (PDT) In-Reply-To: References: Date: Wed, 7 Aug 2013 01:16:39 +0100 Subject: Re: Newbie: static typing? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375834607 news.xs4all.nl 15865 [2001:888:2000:d::a6]:33440 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52093 On Wed, Aug 7, 2013 at 12:02 AM, Terry Reedy wrote: > 3) The code falls into an infinite loop or recursion. > > The solution is to think before looping or recursing. This often involves > value checking (non-negative int or non-fractional float, for instance) > rather than type checking in the usual static type-checking sense. Yeah, there aren't many languages that let you declare that the argument must be a positive integer. That's just something you have to test for manually. > One also needs to be careful about passing unbounded iterators to other > functions and remember that unboundedness is contagious. (filter(pred, > unbounded_iterator) is an unbounded iterator). Again, this is a 'value' or > implicit sub-type issue rather than a explicit, visible 'type' issue. Not quite always; I'd say that unboundedness is as contagious as IEEE Infinity. Lots of operations on infinity will yield infinity, but a few won't. itertools.islice can guarantee a finite iterator, and takewhile may terminate. But yes, with filter() it certainly is. ChrisA