Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Add exist_ok parameter to registrable.register decorator. #3190

Merged
merged 8 commits into from
Aug 22, 2019

Conversation

nelson-liu
Copy link
Contributor

No description provided.

@nelson-liu nelson-liu requested a review from joelgrus August 22, 2019 19:24
Copy link
Contributor

@joelgrus joelgrus left a comment

Choose a reason for hiding this comment

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

I just made up this idea off the top of my head 😬

anyway, you should (1) add a docstring to register explaining what exist_ok does, and (2) add logging in the exist_ok case that basically says something like f"{name} has already been used to register {existing_class} but exist_ok is True so overwriting with {new_class}"

@nelson-liu
Copy link
Contributor Author

I just made up this idea off the top of my head 😬

Should I not be trusting ideas that you make up off the top of your head? 😄

anyway, you should (1) add a docstring to register explaining what exist_ok does, and (2) add logging in the exist_ok case that basically says something like f"{name} has already been used to register {existing_class} but exist_ok is True so overwriting with {new_class}"

Good ideas, added.

Copy link
Contributor

@joelgrus joelgrus left a comment

Choose a reason for hiding this comment

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

approved, modulo my comments

allennlp/common/registrable.py Outdated Show resolved Hide resolved
allennlp/common/registrable.py Outdated Show resolved Hide resolved
allennlp/common/registrable.py Outdated Show resolved Hide resolved
allennlp/common/registrable.py Outdated Show resolved Hide resolved
@nelson-liu nelson-liu merged commit 7738cb5 into allenai:master Aug 22, 2019
@nelson-liu nelson-liu deleted the registerable_exist_ok branch August 22, 2019 20:52
registry[name] = subclass
return subclass
return add_subclass_to_registry

@classmethod
def by_name(cls: Type[T], name: str) -> Type[T]:
logger.debug(f"instantiating registered subclass {name} of {cls}")
logger.info(f"instantiating registered subclass {name} of {cls}")
Copy link
Contributor

Choose a reason for hiding this comment

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

@nelson-liu I wonder why this was changed, which is reverting #2004

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a bug to me. PR welcome!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry yes, this is a bug, thanks for pointing it out.

reiyw pushed a commit to reiyw/allennlp that referenced this pull request Nov 12, 2019
* Add exist_ok parameter to registrable.register decorator.

* Fix pylint.

* Fix pylint.

* Add docstring for registrable.register.

* Add a space to appease pylint.

* Switch if not exist_ok to else.

* Switch to fstrings.

* Change logger.debug to logger.info
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants