Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'method.': 0.07; 'falls': 0.09; 'here?': 0.09; 'method,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'behaviour.': 0.16; 'finney': 0.16; 'mro': 0.16; 'raised.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'meant': 0.20; 'header:User- Agent:1': 0.23; 'controlling': 0.24; 'pass': 0.26; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'asked': 0.31; 'code': 0.31; 'writes:': 0.31; 'anyone': 0.31; 'class': 0.32; 'skip:m 30': 0.32; 'problem': 0.35; 'tool': 0.35; 'but': 0.35; 'method': 0.36; 'subject:?': 0.36; 'should': 0.36; 'clear': 0.37; 'ben': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'back': 0.62; 'skip:n 10': 0.64; 'provide': 0.64; 'more': 0.64; '8bit%:21': 0.69; 'internet': 0.71; '8bit%:27': 0.74; '\xe2\x80\x93': 0.77; 'improvement': 0.84; 'good,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Newbie: static typing? Date: Wed, 07 Aug 2013 08:34:20 +1000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: rasputin.madmonks.org X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:lexrzLCadZZbHJCx/wF9ZUgAIGo= 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375828475 news.xs4all.nl 15923 [2001:888:2000:d::a6]:56250 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52075 Rui Maciel writes: > class AbstractVisitor(object): > def visit(self, element): > pass A small improvement to your code: If you want an abstract method – that is, a method which should not be called directly but which sub-classes should over-ride – then your abstract method should not ‘pass’. Instead, it should ‘raise NotImplementedError’ so this will be clear to anyone if the MRO falls back to the abstract method. > not_a_valid_type = "foo" > > model.accept(not_a_valid_type) At this point, the ‘not_a_valid_type’ object is asked for its ‘visit’ method, and a TypeError is raised. That's good, because it informs the person looking at the code that this object doesn't support the needed behaviour. This is as it's meant to be; what problem are you pointing out here? -- \ “Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.” —Anthony Taylor | Ben Finney