Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52213

RE: Newbie: static typing?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; 'completeness': 0.07; 'arguments': 0.09; 'happen.': 0.09; 'raises': 0.09; 'received:155': 0.09; 'type,': 0.09; 'python': 0.11; 'def': 0.12; 'bug': 0.12; 'added.': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'inheritance': 0.16; 'manifest': 0.16; 'mixture': 0.16; 'pythonic': 0.16; 'received:155.180': 0.16; 'received:159': 0.16; 'received:159.53': 0.16; 'received:169.70': 0.16; 'received:169.70.184': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'securities,': 0.16; 'threw': 0.16; 'types,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'attach': 0.16; 'wrote:': 0.18; '(not': 0.18; 'code.': 0.18; '(but': 0.19; 'typing': 0.19; 'later': 0.20; 'code,': 0.22; 'aug': 0.22; 'issue.': 0.22; 'to:name:python-list@python.org': 0.22; 'error': 0.23; "aren't": 0.24; 'header:Received:8': 0.24; 'sort': 0.25; "i've": 0.25; 'certain': 0.27; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'to:2**1': 0.27; 'point': 0.28; 'function': 0.29; 'testing': 0.29; 'chris': 0.29; 'am,': 0.29; 'mix': 0.30; 'especially': 0.30; 'usually': 0.31; 'safely': 0.31; 'languages': 0.32; 'received:169.254': 0.32; 'bugs': 0.33; 'older': 0.33; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'accuracy': 0.36; 'raising': 0.36; 'surely': 0.36; 'useful': 0.36; 'charset :us-ascii': 0.36; 'subject:?': 0.36; 'similar': 0.36; 'url:org': 0.36; 'received:169': 0.37; 'too': 0.37; 'being': 0.38; 'problems': 0.38; 'ends': 0.38; 'handle': 0.38; 'to:addr:python- list': 0.38; 'rather': 0.38; 'url:2004': 0.39; 'does': 0.39; 'itself': 0.39; 'url:12': 0.39; 'to:addr:python.org': 0.39; 'future': 0.60; 'most': 0.60; 'new': 0.61; 'information,': 0.61; 'making': 0.63; 'personal': 0.63; 'happen': 0.63; 'more': 0.64; 'purchase': 0.65; 'spot': 0.65; 'to:addr:gmail.com': 0.65; 'invalid': 0.68; 'reads': 0.68; 'subject': 0.69; 'legal': 0.71; 'sale': 0.75; 'received:169.254.8': 0.84; 'remember,': 0.93; '2013': 0.98
X-DKIM OpenDKIM Filter v2.1.3 sf2.jpmchase.com r78GkJGb003038
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1375980379; bh=UYjExUI/lHU9u2ZyDfUeZQDpKGnikXKARZb6JPJMAkA=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:content-transfer-encoding:MIME-Version; b=qxW9XkxIaNZSF+634i44wliyIBe9C50V8zLW+U1K+oSb/lkOa8IS+E3kKS3xv0+UP XW5E/MZ5pMqkmyJRIwHpWc17spRrYuiSdqGhYij3bVY+iJuZ7gPvWC4QKpoZX4ulKy 94XYpW9AZh+KzJgEHbepaGpy75nfuLzMXf/o+eDc=
X-AuditID a959dcad-b7f848e000002ba4-1d-5203cb5a5fef
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
To "rui.maciel@gmail.com" <rui.maciel@gmail.com>, "python-list@python.org" <python-list@python.org>
Subject RE: Newbie: static typing?
Thread-Topic Newbie: static typing?
Thread-Index AQHOko+k2wcq/oXgRkS+Ng4sj/OLBJmLhTIA
Date Thu, 8 Aug 2013 16:46:03 +0000
References <ktp2jh$3a3$1@dont-email.me> <mailman.223.1375749359.1251.python-list@python.org> <ktqdkq$v3k$1@dont-email.me> <mailman.233.1375781390.1251.python-list@python.org> <ktqin6$n5u$1@dont-email.me>
In-Reply-To <ktqin6$n5u$1@dont-email.me>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Type text/plain; charset="us-ascii"
content-transfer-encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
X-Brightmail-Tracker H4sIAAAAAAAAA+NgFmpnk+LIzCtJLcpLzFFi42JZ6Wptoxt9mjnIYNp8NosjrddYLdZ3L2B2 YPLYOesuu8eL+W/YApiiGhhtEvPy8ksSS1IVUlKLk22VXDKLk3MSM3NTixR0FbwKcvOL0hPz 9JLzc5UUMlNslUyUFApyEpNTc1PzSmyVEgsKUvNSlOy4FDCADVBZZp5Cal5yfkpmXrqtkmew v66FhamlrqGSXUhGZrFCam5iZo5Cwkb2jNkTPzMX3BeoWDSpkb2BcSlvFyMHh4SAicSlaVld jJxAppjEhXvr2boYuTiEBA4zSrxbuQ/KOcAo8elwO4Jza9oTdghnI6PEzy19jCD9bAKGEsfP giQ4OUQE0iTmzm8FiwsLKEvMevKRBSKuItG1/CwzhG0k8a1/B5jNAhTf13OVDcTmFQiRaFh4 lRViwRVGiT+T9rCC3MopoCmx9mopSA0j0K3fT61hArGZBcQlbj2ZzwTxg4DEkj3nmSFsUYmX j/+xQtjyEi+mvGSDqNeRWLD7E5StLbFs4WtmiL2CEidnPmEBWSUkoCaxb70tJIT4JLa3VU9g lJyFZNksJINmIRk0C8mgBYwsqxgli3PTs4z0isuK9EqL9bIKcpMzEotT9fJSSzYxgtJP5J21 OxiXd9seYhTgYFTi4T2xhTlIiDWxrLgy9xCjBAezkghv46aNgUK8KYmVValF+fFFpTmpxYcY q4BhNpFZSjQ5H5ga80riDY3NLAxMTQ0NLAyNTKgirCTOKy3PGCQkkA5MttmpqQWpRTDLmTg4 pRoYc9s5mt3XnDgZ6338ULjO8SV382ozpJ48aGVfaZ8v+VnS8Mejnox3BaGJlzgVNTKdJ5Zc PVpg8HzpHfnPyr8q0pRmt19+7ZhX9GsaF9ftGcK3v5z99Y3x/2rd/Mdb/d+7bhFg+B3JE340 TuROtWS14m7O1k9eusnPX/4MjVrkKhHXf35D7ds/SizFGYmGWsxFxYkADWingpoDAAA=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.362.1375980469.1251.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375980469 news.xs4all.nl 15940 [2001:888:2000:d::a6]:39173
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52213

Show key headers only | View raw


Rui Maciel wrote:
> Chris Angelico wrote:
> 
> > On Tue, Aug 6, 2013 at 10:01 AM, Rui Maciel <rui.maciel@gmail.com> wrote:
> >> It would be nice if some functions threw an error if they were passed a
> >> type
> >> they don't support or weren't designed to handle.  That would avoid
> >> having to deal with some bugs which otherwise would never happen.
> >>
> >> To avoid this sort of error, I've been testing arguments passed to some
> >> functions based on their type, and raising TypeError when necessariy, but
> >> surely there must be a better, more pythonic way to handle this issue.
> >
> > def add_three_values(x,y,z):
> >     return x+y+z
> >
> > Do you want to test these values for compatibility? Remember, you
> > could take a mixture of types, as most of the numeric types can safely
> > be added. You can also add strings, or lists, but you can't mix them.
> > And look! It already raises TypeError if it's given something
> > unsuitable:
> 
> If the type problems aren't caught right away when the invalid types are
> passed to a function then the problem may only manifest itself in some far
> away point in the code, making this bug needlessly harder to spot and fix,
> and making the whole ordeal needlessly too time consuming.
> 
> 
> Rui Maciel

This can be true, but in personal experience does not happen 
often. I will say that dynamic typing ends up usually
being more future proof as I can later create a similar object
(but not in the same inheritance hierarchy) that will work
with older functions because the functions don't look for
certain types but rather just rely on duck typing.

I find this especially useful when testing or mocking. I can
create a test object and attach methods/attributes to the
test object to duck type as I desire to test the my desired code. 

I think the following reads are very interesting
for people new to Python from other languages (not just Java).
http://dirtsimple.org/2004/12/python-is-not-java.html
(and the flip side) http://dirtsimple.org/2004/12/java-is-not-python-either.html


~Ramit



This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-05 21:46 +0100
  Re: Newbie: static typing? Gary Herron <gary.herron@islandtraining.com> - 2013-08-05 14:07 -0700
    Re: Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-06 10:05 +0100
      Re: Newbie: static typing? Steven D'Aprano <steve@pearwood.info> - 2013-08-06 09:26 +0000
      Re: Newbie: static typing? Joshua Landau <joshua@landau.ws> - 2013-08-06 10:29 +0100
        Re: Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-06 11:12 +0100
          Re: Newbie: static typing? Burak Arslan <burak.arslan@arskom.com.tr> - 2013-08-06 16:27 +0300
          Re: Newbie: static typing? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-06 15:57 +0200
          Re: Newbie: static typing? Chris Angelico <rosuav@gmail.com> - 2013-08-06 15:06 +0100
          Re: Newbie: static typing? "Eric S. Johansson" <esj@harvee.org> - 2013-08-06 09:58 -0400
          Re: Newbie: static typing? Chris Angelico <rosuav@gmail.com> - 2013-08-06 15:38 +0100
      Easier to Ask Forgiveness than Permission (was: Newbie: static typing?) Ben Finney <ben+python@benfinney.id.au> - 2013-08-07 08:23 +1000
  Re: Newbie: static typing? Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-05 17:38 -0600
  Re: Newbie: static typing? Ben Finney <ben+python@benfinney.id.au> - 2013-08-06 10:35 +1000
    Re: Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-06 10:01 +0100
      Re: Newbie: static typing? Joshua Landau <joshua@landau.ws> - 2013-08-06 10:19 +0100
        Re: Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-06 11:07 +0100
          Re: Newbie: static typing? Rotwang <sg552@hotmail.co.uk> - 2013-08-06 15:25 +0100
          Re: Newbie: static typing? Ben Finney <ben+python@benfinney.id.au> - 2013-08-07 08:34 +1000
      Re: Newbie: static typing? Chris Angelico <rosuav@gmail.com> - 2013-08-06 10:29 +0100
        Re: Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-06 11:28 +0100
          Re: Newbie: static typing? Chris Angelico <rosuav@gmail.com> - 2013-08-06 11:50 +0100
          Re: Newbie: static typing? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-06 18:54 -0400
          Re: Newbie: static typing? Terry Reedy <tjreedy@udel.edu> - 2013-08-06 19:02 -0400
          Re: Newbie: static typing? Chris Angelico <rosuav@gmail.com> - 2013-08-07 01:16 +0100
          RE: Newbie: static typing? "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid> - 2013-08-08 16:46 +0000
  Re: Newbie: static typing? Steven D'Aprano <steve@pearwood.info> - 2013-08-06 05:21 +0000
    Re: Newbie: static typing? Rui Maciel <rui.maciel@gmail.com> - 2013-08-06 10:04 +0100
  Re: Newbie: static typing? Grant Edwards <invalid@invalid.invalid> - 2013-08-06 15:05 +0000

csiph-web