Skip to content

Automatically Detect Argument Defaults in attrs-Equivalent Decorators #12775

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

t4lz
Copy link
Contributor

@t4lz t4lz commented May 12, 2022

Description

Fixes #12774

Instead of relying only on hardcoded default value, first try to find out the actuall default value of a bool argument to a the class/attrib-maker decorators, and only if the value could not be extracted from the code, fall back to the default value defined in mypy.

This enables the correct handling of decorators which wrap attrs decorators but set different defaults, for example to kw_only.

Test Plan

This commit also adds two test cases. testAttrsWrappedDecorators tests the existing support for wrapping attrs decorators, via a "fake plugin" and testAttrsWrappedDecoratorsWithDifferentDefaults tests the new support for decorators that have different default values than the attrs decorators.

@t4lz t4lz changed the title Automatically detect decorator argument default. Automatically Detect Argument Defaults in attrs-Equivalent Decorators May 12, 2022
@github-actions

This comment has been minimized.

@t4lz t4lz force-pushed the attrs-wrappers-support branch from 9111471 to 89dec25 Compare May 16, 2022 09:29
@t4lz
Copy link
Contributor Author

t4lz commented May 16, 2022

Rebased on master and fixed fail.

@github-actions

This comment has been minimized.

Instead of relying only on hardcoded default value, first try to find
out the actuall default value of a bool argument to a the
class/attrib-maker decorators, and only if the value could not be
extracted from the code, fall back to the default value defined in mypy.

This enables the correct handling of decorators which wrap attrs
decorators but set different defaults, for example to kw_only.

This commit also adds to test cases. testAttrsWrappedDecorators tests
the existing support for wrapping attrs decorators, via a "fake plugin"
and testAttrsWrappedDecoratorsWithDifferentDefaults tests the new
support for decorators that have different default values than the attrs
decorators.
@t4lz t4lz force-pushed the attrs-wrappers-support branch from 89dec25 to d661abb Compare June 23, 2022 08:22
@github-actions

This comment has been minimized.

@t4lz
Copy link
Contributor Author

t4lz commented Jun 29, 2022

I think I'm ready for review :)

@t4lz
Copy link
Contributor Author

t4lz commented Aug 5, 2022

Hey, is it likely this PR would be reviewed if I resolve the new conflicts?

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@t4lz t4lz force-pushed the attrs-wrappers-support branch from 9f5a3d9 to ee91e41 Compare August 16, 2022 07:31
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

Supporting attrs extensions with different default arguments for decorators.
1 participant