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

Make nodes.template.Template a bit more dict-like #252

Merged
merged 5 commits into from
Sep 7, 2020

Conversation

AntiCompositeNumber
Copy link
Contributor

@AntiCompositeNumber AntiCompositeNumber commented Aug 19, 2020

  • Adds a default parameter to Template.get that can be returned instead of raising an exception. If the parameter is not specified, previous behavior is maintained.
  • Adds __getitem__, __setitem__, and __delitem__ methods to Template, allowing the use of Template[param] syntax.
  • Adds a __contains__ method to Template, allowing the use of key in Template syntax
  • Uses a def instead of a lambda assignment for has_param (PEP8)

Template.get should really raise a KeyError, not a ValueError, but implementing that would be a breaking change.

Similar to dict.get, Template.get with a default param supplied will
return that value instead of raising an exception. If default is unset,
Template.get will keep its previous behavior and raise an exception.
These are just aliases for existing methods, without the ability to
specifiy additional parameters. However, including them makes Template
more dict-like, so it's a good idea to have them.
Per PEP8, there is no benefit to using a lambda here, and some
downsides. It's the same number of SLOC either way, so might as well
change it.
This allows the use of `key in Template` syntax
@coveralls
Copy link

coveralls commented Aug 19, 2020

Coverage Status

Coverage decreased (-0.1%) to 99.159% when pulling 64691b9 on AntiCompositeNumber:slice into 8c4b592 on earwig:develop.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 99.161% when pulling 64691b9 on AntiCompositeNumber:slice into 8c4b592 on earwig:develop.

@earwig
Copy link
Owner

earwig commented Sep 7, 2020

Sorry I took a while to get to this—looks good. The CI failure can be ignored; I'll remove Python 3.4 from the supported versions.

@earwig earwig merged commit f241829 into earwig:develop Sep 7, 2020
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.

3 participants