Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up aliases in campbells.formatter with a classmethod #1

Closed
lmmx opened this issue Aug 25, 2023 · 0 comments
Closed

Set up aliases in campbells.formatter with a classmethod #1

lmmx opened this issue Aug 25, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@lmmx
Copy link
Owner

lmmx commented Aug 25, 2023

At the end of formatter.py, aliases are set using the REGISTRY class var and the __init__ methods of the Formatter subclasses HTMLFormatter and XMLFormatter:

class HTMLFormatter(Formatter):
"""A generic Formatter for HTML."""
REGISTRY = {}
def __init__(self, *args, **kwargs):
super().__init__(self.HTML, *args, **kwargs)
class XMLFormatter(Formatter):
"""A generic Formatter for XML."""
REGISTRY = {}
def __init__(self, *args, **kwargs):
super().__init__(self.XML, *args, **kwargs)
# Set up aliases for the default formatters.
HTMLFormatter.REGISTRY["html"] = HTMLFormatter(
entity_substitution=EntitySubstitution.substitute_html,
)
HTMLFormatter.REGISTRY["html5"] = HTMLFormatter(
entity_substitution=EntitySubstitution.substitute_html,
void_element_close_prefix=None,
empty_attributes_are_booleans=True,
)
HTMLFormatter.REGISTRY["minimal"] = HTMLFormatter(
entity_substitution=EntitySubstitution.substitute_xml,
)
HTMLFormatter.REGISTRY[None] = HTMLFormatter(entity_substitution=None)
XMLFormatter.REGISTRY["html"] = XMLFormatter(
entity_substitution=EntitySubstitution.substitute_html,
)
XMLFormatter.REGISTRY["minimal"] = XMLFormatter(
entity_substitution=EntitySubstitution.substitute_xml,
)
XMLFormatter.REGISTRY[None] = Formatter(
Formatter(Formatter.XML, entity_substitution=None),
)

This is not a great pattern, instead use a classmethod to make it clearer what is in common (this section is hard to read)

@lmmx lmmx converted this from a draft issue Aug 25, 2023
@lmmx lmmx self-assigned this Aug 25, 2023
@lmmx lmmx added the enhancement New feature or request label Aug 25, 2023
@lmmx lmmx closed this as completed in 317464c Aug 26, 2023
@github-project-automation github-project-automation bot moved this from 🔜 Soon to ✅ Done in Campbells Soup Kitchen Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

1 participant