Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; '(python': 0.07; '(pos': 0.09; 'obj': 0.09; 'override': 0.09; 'subject:method': 0.09; 'def': 0.12; 'foo()': 0.16; 'typeerror:': 0.16; 'sender:addr:gmail.com': 0.17; 'subject:] ': 0.20; 'seems': 0.21; 'import': 0.22; '(such': 0.24; 'pass': 0.26; 'message- id:@mail.gmail.com': 0.30; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'implemented': 0.33; 'skip:_ 10': 0.34; 'classes': 0.35; 'received:google.com': 0.35; 'method': 0.36; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; 'subject:[': 0.39; 'to:addr:python.org': 0.39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=s+f4dDErlKy6bfnUflmQtyIOtByJ1DY0LBoMxOF1Frg=; b=lxRmVg/ofhkDw9qir6QiETv1K7xSubYFktHo4+3wo21twF6C+/EpnMVs+UU8o69/Yg uRbqqPcWY5R8DOfKUDKaBplADaxrvVcgmnZz5kycvHRTHOff+RuHNnVh5HWl9A5YxwY+ QhM1HVmLgxM1fWhhF9aLZ2AHAODWWUo3LEbWDgsJfUiAJf0+ysj2hzQhV1F+1aPYzp4G inR6hjXCc3SSGkKbrwqEHggkPwt8ZoNBrX+imMEMSK/97D4tGhovEG5sr8yL53cRgNX6 D63thcC7hyYMPF64jpTj96ibtWzGTLaf37CV2WHncwNVCXwa6qpabGxBGQe7OyH78XAa S4ww== MIME-Version: 1.0 X-Received: by 10.140.29.139 with SMTP id b11mr54233306qgb.44.1404114334639; Mon, 30 Jun 2014 00:45:34 -0700 (PDT) Sender: kwatch@gmail.com Date: Mon, 30 Jun 2014 16:45:34 +0900 X-Google-Sender-Auth: pf-kbTKUp8x7O0odoA7YnJQsgZM Subject: [Q] override __init__() method of classes implemented in C From: Makoto Kuwata To: python-list@python.org Content-Type: multipart/alternative; boundary=001a113a76ca23f08904fd08d8de 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: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404114338 news.xs4all.nl 2859 [2001:888:2000:d::a6]:50741 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73740 --001a113a76ca23f08904fd08d8de Content-Type: text/plain; charset=UTF-8 Is it impossible to override __init__() method of classes implemented in C (such as datetime.datetime) ? example.py: from datetime import datetime class Foo(datetime): def __init__(self): pass obj = Foo() Result (Python 2.7.7 and 3.4.1): Traceback (most recent call last): File "hoge.py", line 7, in obj = Foo() TypeError: Required argument 'year' (pos 1) not found It seems to be failed to override datetime.__init__() in subclass. -- regards, makoto kuwata --001a113a76ca23f08904fd08d8de Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Is it impossible to override __init__() method of cla= sses
implemented in C (such as datetime.datetime) ?

example.py:

from datetime import datetime
class Foo(datetime):
<= span class=3D"" style=3D"white-space:pre"> =C2=A0 =C2=A0def __init_= _(self):
=C2=A0 =C2=A0 =C2=A0 = =C2=A0pass
obj =3D Foo()


Result (Python 2.7.7 and 3.4.1):

Traceback (most recent call last):<= /div>
=C2=A0File &q= uot;hoge.py", line 7, in <module>
=C2=A0 =C2=A0obj = =3D Foo()
Type= Error: Required argument 'year' (pos 1) not found


It seems to be failed to override datetime.__init__() in subclass.


--
regards,
makoto= kuwata
--001a113a76ca23f08904fd08d8de--