Skip to content

Conversation

@embray
Copy link
Member

@embray embray commented Dec 1, 2014

These automatically add TimeFormat classes to the TIME_FORMAT and TIME_DELTA_FORMAT dicts at class creation time instead of after the fact. This should also reduce the effort required to define new formats external to Astropy. This may understandably look overengineered, but it does have the advantage of fixing the annoyance mentioned here: #3095 (comment) by not doing any module-level hackery.

@embray
Copy link
Member Author

embray commented Dec 1, 2014

There's no test I could write that demonstrates the problem with doctests that this fixes, but basically when iterating over locals() it was leaving behind some local variables with the names name and val. The doctest runner could sometimes pick up whatever was defined as val and look in that variable for doctests. If this happened to be TimePlotDate (which could happen at random depending on what order the keys in locals() were iterated over), then the doctest runner would fail to skip that test since it was named "val" instead of "TimePlotDate".

@taldcroft
Copy link
Member

@embray - 👏 on figuring this out. This looks good to me from the Time perspective, and I actually like the metaclass registration here.

@embray
Copy link
Member Author

embray commented Dec 2, 2014

Weird that this seemed to cause so many tests to break. I didn't have any problem running them locally.

@mhvk
Copy link
Contributor

mhvk commented Dec 2, 2014

@embray - I had to think a little, but this does seem quite a bit more elegant than the loop that was there, so 👍! (Out of curiosity, just deleting name and val after the loop should have worked as well, correct?)

Though obviously something is still amiss, since the travis failues suggests Time can never be initialized any more... I'll try to investigate.

I also cannot think of a good test, though now that we are making introducing a new Time format easier, it may be good to give an example in the docs and test that. But that is for another issue/PR.

@embray
Copy link
Member Author

embray commented Dec 2, 2014

@mhvk You are correct, that probably should have fixed the original issue, but it was easy enough to take this the rest of the way. No idea why the tests are all bombing out now, since it worked fine locally. It's probably something simple that I'll have figured out shortly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this should have been mcls._registry[cls.name] = cls. I probably had that before and then accidentally deleted it at the last second or something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, found that too. And with that all tests pass for me.

@mhvk
Copy link
Contributor

mhvk commented Dec 2, 2014

OK, the keys to FORMATS are now class names (cls.__name__, I think), while they used to be cls.name, i.e., attributes set in the different format classes.

…ormat classes to the TIME_FORMAT and TIME_DELTA_FORMAT dicts at class creation time instead of after the fact. This should also reduce the effort required to define new formats external to Astropy. This may understandably look overengineered, but it does have the advantage of fixing the annoyance mentioned here: astropy#3095 (comment) by not doing any module-level hackery.
@embray embray force-pushed the time/time-format-registry branch from 090b6a5 to 4ce98b9 Compare December 2, 2014 15:24
@embray embray added this to the v1.0.0 milestone Dec 2, 2014
@taldcroft
Copy link
Member

@mhvk - I don't quite follow your comment. The keys to *_FORMATS are still cls.name (formally val.name where val was the class). Or am I misinterpreting?

@embray
Copy link
Member Author

embray commented Dec 2, 2014

@taldcroft You are--I just pushed a fixed up commit.

@taldcroft
Copy link
Member

Ah, I had the time order of commit and comment swapped in my head.

@embray embray added the Affects-dev PRs and issues that do not impact an existing Astropy release label Dec 2, 2014
embray added a commit that referenced this pull request Dec 2, 2014
Add TimeFormatMeta and TimeDeltaFormatMeta
@embray embray merged commit 143258a into astropy:master Dec 2, 2014
@embray embray deleted the time/time-format-registry branch December 2, 2014 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release Bug Enhancement testing time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants