Return factory from hook factory decorator functions#724
Open
bysiber wants to merge 1 commit intopython-attrs:mainfrom
Open
Return factory from hook factory decorator functions#724bysiber wants to merge 1 commit intopython-attrs:mainfrom
bysiber wants to merge 1 commit intopython-attrs:mainfrom
Conversation
register_unstructure_hook_factory and register_structure_hook_factory
can be used as decorators, but the inner decorator function doesn't
return the factory. This means:
@converter.register_structure_hook_factory(has)
def my_factory(type):
...
# my_factory is now None
The type annotations declare these decorators should return the factory
(Callable[[Factory], Factory]) and the non-decorator path already
works correctly. This just adds the missing return statement.
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.
register_unstructure_hook_factoryandregister_structure_hook_factorycan be used as decorators (documented since 24.1.0), but the innerdecoratorfunction doesn't return the factory. This means:The type annotations already declare the correct contract (
Callable[[Factory], Factory]), and internal uses discard the return value, so this only affects external users who use the decorator syntax and later reference the decorated function.Fix: add
return factoryat the end of bothdecoratorfunctions.