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


Groups > comp.lang.python > #73741 > unrolled thread

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

Started byChris Angelico <rosuav@gmail.com>
First post2014-06-30 17:52 +1000
Last post2014-06-30 17:52 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromChris Angelico <rosuav@gmail.com>
Date2014-06-30 17:52 +1000
SubjectRe: [Q] override __init__() method of classes implemented in C
Message-ID<mailman.11336.1404114745.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web