-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add exist_ok parameter to registrable.register decorator. #3190
Conversation
There was a problem hiding this 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}"
Should I not be trusting ideas that you make up off the top of your head? 😄
Good ideas, added. |
There was a problem hiding this 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
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}") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
* 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
No description provided.