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


Groups > comp.lang.python > #73741

Re: [Q] override __init__() method of classes implemented in C

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.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; 'subject:: [': 0.04; 'argument': 0.05; '(python': 0.07; '(pos': 0.09; '__init__': 0.09; 'obj': 0.09; 'override': 0.09; 'subject:method': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; '__new__': 0.16; 'foo()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; 'seems': 0.21; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'skip:_ 10': 0.34; 'maybe': 0.34; 'problem': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'issue': 0.38; 'pm,': 0.38; 'recent': 0.39; 'is.': 0.60; "you're": 0.61; '30,': 0.65; 'actually,': 0.84; 'to:none': 0.92
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:cc :content-type; bh=TGJ+aP246tshTzc2NeKX2x+4fU3uYxcktoa95OGvJv0=; b=tiXCkIq+zBmARvEj5tZl3joVicsj8ouS/CvCJ1w4j6hxLE9G77Th4KlBGyOwuFve+9 T+bq9jLS7amXkpJwOPZm4NY8UWdMNWvTUQD3UF3JgKrTcvSLDnrAiIvcH9LppZDUhNu4 xtsfypgz6qjcqMLaRVka0gZqQxhihnsGQbFkawpyo8QjyEBATm0shwk0bQ2uBSQgJrJF 3iGpzzc55jRFgeRqgkJ+UL6V7yt2AKQX9gyLllS3bdtp6S+YRUt10VXCQXTPKkn9csdt aGrwBBYcylqWWgwTJqFdOMZt0q5FKT4yyw8bBpmeOhFrgl4VGqGrMfJsAXABQtXrYRyd 9abw==
MIME-Version 1.0
X-Received by 10.221.9.72 with SMTP id ov8mr36685639vcb.27.1404114737656; Mon, 30 Jun 2014 00:52:17 -0700 (PDT)
In-Reply-To <CAFTm5RvAmdDQSe03mekY-26Zm+Eu-qWwN5W=L1NUre9KPRg77w@mail.gmail.com>
References <CAFTm5RvAmdDQSe03mekY-26Zm+Eu-qWwN5W=L1NUre9KPRg77w@mail.gmail.com>
Date Mon, 30 Jun 2014 17:52:17 +1000
Subject Re: [Q] override __init__() method of classes implemented in C
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11336.1404114745.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404114745 news.xs4all.nl 2905 [2001:888:2000:d::a6]:53459
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73741

Show key headers only | View raw


On Mon, Jun 30, 2014 at 5:45 PM, Makoto Kuwata <kwa@kuwata-lab.com> wrote:
> Result (Python 2.7.7 and 3.4.1):
>
> Traceback (most recent call last):
>  File "hoge.py", line 7, in <module>
>    obj = Foo()
> TypeError: Required argument 'year' (pos 1) not found
>
>
> It seems to be failed to override datetime.__init__() in subclass.
>

Actually, __init__ isn't the problem here, __new__ is.

class Foo(datetime):
    def __new__(self):
        return super().__new__(self,2014,1,1)

>>> Foo()
Foo(2014, 1, 1, 0, 0)

Maybe that helps, maybe it doesn't, but the issue you're seeing is
specific to that class.

ChrisA

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


Thread

Re: [Q] override __init__() method of classes implemented in C Chris Angelico <rosuav@gmail.com> - 2014-06-30 17:52 +1000

csiph-web