This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: return val in __init__ doesn't raise TypeError in new-style
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: moese, rhettinger
Priority: normal Keywords:

Created on 2005-04-15 19:16 by moese, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg25036 - (view) Author: Moese (moese) Date: 2005-04-15 19:16
returning a value (other than None) from __init__ is
supposed to raise TypeError. This only works for
old-style classes.
msg25037 - (view) Author: Moese (moese) Date: 2005-04-15 19:20
Logged In: YES 
user_id=1067739

# I've failed to attach this file so I've added a comment.
This should be modified to report eventual failure and added
to the test library.

class LegalConstructor1(object):

    def __init__(self):
        return

class LegalConstructor2(object):

    def __init__(self):
        return None

class IlegalConstructor(object):

    def __init__(self):
        return "x"

class LegalConstructorOld1:

    def __init__(self):
        return

class LegalConstructorOld2:

    def __init__(self):
        return None

class IlegalConstructorOld:

    def __init__(self):
        return "x"

a = LegalConstructor1()
print a

b = LegalConstructor2()
print b

x = LegalConstructorOld1()
print a

y = LegalConstructorOld2()
print b

# !!! This should raise TypeError
c = IlegalConstructor()
print c

z = IlegalConstructorOld()
print z
msg25038 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-04-18 17:11
Logged In: YES 
user_id=80475

This has been fixed for 2.4.1 where a RuntimeWarning is
raised and in 2.5.0a where a TypeError is raised.
History
Date User Action Args
2022-04-11 14:56:10adminsetgithub: 41864
2005-04-15 19:16:56moesecreate