Repository navigation
Add a silly automatic registry of known formatter classes - #2852
Merged
Merged
Conversation
…antage of enabling user-defined formatters. astropy.units.format.__init__ should still import all the built-in formatters to ensure they are added to the registry, so this is a minimal change.
Member
Author
|
It appears this did not go over so well on Python 2 (I use Python 3 by default now). I'll get to the bottom of things... |
…ase) and include a type check in case the format is not a valid string.
Member
Author
|
Updated with a few small fixes for cross-compat, as well as some extra type checking that wasn't there before, along with a more useful exception message for when the requested formatter isn't found. |
Member
Author
|
@mdboom Any objections to this? |
Contributor
|
@embray - looks good to me. |
Contributor
|
Looks good to me. I restarted Travis now that (I think) the Numpy doc issue is fixed. |
mdboom
added a commit
that referenced
this pull request
Aug 25, 2014
Add a silly automatic registry of known formatter classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One advantage of doing things this way, is that it enables user-defined unit formatters (all one has to do is define a subclass of
astropy.units.format.Base). This should generally be discouraged, but at the same time it's good to have the ability available when absolutely necessary.This also allows the name used to look up a formatter to be different from the class name. This was motivated primarily by my rambling here. All formatter classes now have a
.nameclass attribute which contains the name they are looked up by. By default this is just__class__.__name__.lower(), but it may be customized. For example in the case of #2622 the class can be defined:where the name
'latex_inline'is perhaps a bit easier on the eyes than'latexinline'.