Skip to content

astropy.constants doesn't import in python3.3 - #603

Merged
astrofrog merged 1 commit into
astropy:masterfrom
astrofrog:fix-constants-python3.3
Jan 11, 2013
Merged

astrofrog merged 1 commit into
astropy:masterfrom
astrofrog:fix-constants-python3.3

Conversation

@astrofrog

Copy link
Copy Markdown
Member

In the 0.2b1 release, astropy.constants doesn't import in python 3.3,
although they do in python 3.2. This was also the case for pre-beta
versions of 0.2.

/sw/lib/python3.3/site-packages/astropy/constants/cgs.py in <module>()
     19 for nm, val in sorted(_cgs.__dict__.items()):
     20     if isinstance(val, ConstantDefinition):
---> 21         _c = Constant(val.value, val.units, val.uncertainty, val.name, val.reference)
     22         locals()[nm] = _c
     23 

/sw/lib/python3.3/site-packages/astropy/constants/constant.py in __new__(cls, value, uncertainty, name, reference, units)
     31 
     32     def __new__(cls, value, uncertainty, name, reference, units):
---> 33         return super(Constant, cls).__new__(cls, value)
     34 
     35     def __repr__(self):

TypeError: object.__new__() takes no parameters

In python3.2, this works correctly.

This problem affects importing pretty much all of the other sub-packages, many of
which do a

from .core import *

resulting in

from ..constants import cgs

This is the current fink version of python33 (3.3.0-3), if that is any help.

@embray

embray commented Jan 10, 2013

Copy link
Copy Markdown
Member

Ah, this just just be super(Constant, cls).__new__(cls); this is subtle but in Python...2.7 I think (?) the object type was changed to not accept any arguments in its constructor. But I guess in Python 3.3 they made that strictly the case. So at the top level of any super call chain in either __new__ or __init__ should be one that doesn't pass on any arguments.

In this case, althought Constant's superclass is actually Quantity, Quantity doesn't implement a custom __new__, so super() resolves straight to object.__new__ and doesn't throw away the arguments passed in on the way.

@embray

embray commented Jan 11, 2013

Copy link
Copy Markdown
Member

In fact, apparently that __new__ is an artifact from what is now the ConstantDefinition class. It can just be removed. It serves no purpose.

@astrofrog

Copy link
Copy Markdown
Member

Oh yes, right - I just did that, so once Travis passes I'll merge.

@embray

embray commented Jan 11, 2013

Copy link
Copy Markdown
Member

Is Travis b0rked or something? It doesn't seem to have even put this PR on its queue.

@astrofrog

Copy link
Copy Markdown
Member

Yeah, it's in the queue, but no nodes are being fired up. However, given that this is a relatively simple change, I'm just going to go ahead and merge. If there are any issues, Jenkins will pick them up.

astrofrog added a commit that referenced this pull request Jan 11, 2013
astropy.constants doesn't import in python3.3
@astrofrog
astrofrog merged commit 3b855c3 into astropy:master Jan 11, 2013
@embray

embray commented Jan 11, 2013

Copy link
Copy Markdown
Member

+1

astrofrog added a commit that referenced this pull request Jan 25, 2013
astropy.constants doesn't import in python3.3
embray added a commit that referenced this pull request Feb 13, 2013
… of #603 in that, because Quantity does not define a __new__ method super().__new__ in Constant.__new__ resolves directly to object.__new__() which is now strict in taking no arguments (would have caught this sooner using 'python -Wd').  This fix is fine because Constant.__init__ also bypasses Quantity.__init__ so there's no need to pass any of the __init__ arguments to the super()'s __new__ call.
embray added a commit that referenced this pull request Feb 13, 2013
… of #603 in that, because Quantity does not define a __new__ method super().__new__ in Constant.__new__ resolves directly to object.__new__() which is now strict in taking no arguments (would have caught this sooner using 'python -Wd').  This fix is fine because Constant.__init__ also bypasses Quantity.__init__ so there's no need to pass any of the __init__ arguments to the super()'s __new__ call.
keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
astropy.constants doesn't import in python3.3
keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
… of astropy#603 in that, because Quantity does not define a __new__ method super().__new__ in Constant.__new__ resolves directly to object.__new__() which is now strict in taking no arguments (would have caught this sooner using 'python -Wd').  This fix is fine because Constant.__init__ also bypasses Quantity.__init__ so there's no need to pass any of the __init__ arguments to the super()'s __new__ call.
@astrofrog
astrofrog deleted the fix-constants-python3.3 branch July 5, 2016 18:46
jeffjennings pushed a commit to jeffjennings/astropy that referenced this pull request Jul 2, 2025
Remove me from coordinates and utils maintainer role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants