Skip to content

Fix test_decorator issue #269 #270

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

Closed
wants to merge 5 commits into from

Conversation

zhiruiluo
Copy link
Contributor

To fix issue #269.

@zhiruiluo zhiruiluo marked this pull request as draft July 1, 2023 22:08
@zhiruiluo
Copy link
Contributor Author

zhiruiluo commented Jul 1, 2023

This doesn't exactly behave like the original partial function via changing defaults.

@zhiruiluo
Copy link
Contributor Author

zhiruiluo commented Jul 2, 2023

Added a delay_evaluation_wrapper to prevent collection error and xfail on two tests.

@zhiruiluo zhiruiluo marked this pull request as ready for review July 2, 2023 19:55
[
("", 1, partial(_fn_with_positional_only, 1)),
("2", 2, partial(_fn_with_positional_only, 1)),
("2", 2, _fn_with_positional_only),
("2", 2, partial(_fn_with_positional_only)),
Copy link
Owner

@lebrice lebrice Jul 5, 2023

Choose a reason for hiding this comment

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

Hey there @zhiruiluo , Would you mind explaining a few things:

  • why is the delay_wrapper necessary here?
  • Did the inspect module change from 3.11 to 3.11.3? Is that what broke this test?

Copy link
Contributor Author

@zhiruiluo zhiruiluo Jul 5, 2023

Choose a reason for hiding this comment

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

The recently PR python/cpython#103557 disallows pos-or-kw params without default after pos-only with default, which breaks the test for Python 3.11.4 released on June 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They will likely backport this change to all Python 3.11 verions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your reply @lebrice. The delay_wrapper can postpone the generation of partial with changing default function until test collected. If the error happens in pytest collection time, we can't use xfail to bypass the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I double checked the backport status. This PR python/cpython#103675 has backport inspect.Signature change to Python 3.11

@zhiruiluo zhiruiluo requested a review from lebrice July 6, 2023 17:06
Copy link
Owner

@lebrice lebrice left a comment

Choose a reason for hiding this comment

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

I don't really understand the change in the inspect module, and I also don't quite understand your changes here either..

I do understand that you want to delay the call to change_signature(fn_with_all_argument_types, 1, c=1) because executing it in Python 3.11.4 raises a ValueError("non-default argument follows default argument").

However, before your change, partial here is meant as change_signature, it makes a variant of a function with a different signature (different default values in the signature).

Here your delayed_wrapper is exactly the same as functools.partial, and when applied to the partial (a.k.a. change_signature, it doesn't change anything, as far as I can tell. Why are you applying it to the change_signature function?

It also seems to my eyes like you are changing the behaviour of the rest of the test cases by only adding this additional level of "delay" to only some of the test cases.

I'm going to re-read your PR, but I'd really appreciate if you could clarify this a bit for me.

@lebrice
Copy link
Owner

lebrice commented Jul 10, 2023

Closed in favour of #273

@lebrice lebrice closed this Jul 10, 2023
@zhiruiluo zhiruiluo deleted the fix_test_decorator branch July 10, 2023 21:03
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.

2 participants