Skip to content
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

Fix built-in method raise exception (#118) #121

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

Conversation

Lonely-Dream
Copy link

针对 #118 中提出的问题尝试做了改善,避免因inspect.signature问题,导致自己库抛出异常。
同步增加了相应的测试用例。


t1 = b""
s = objstr(t1, print_methods=True, honor_existing=False)
is_python_le_3_13 = sys.version_info <= (3, 13)
Copy link
Owner

Choose a reason for hiding this comment

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

You don't need a separate variable here. The expression is very clear. Also don't need to test 3.13+, just confirm we get the special case for 3.13- would be fine.

Copy link
Author

Choose a reason for hiding this comment

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

OK, I will delete this variable. You mentioned in the #118 that the new version will fix this problem. I understand that <signature unknown> should not appear in the new version, so I added the version judgment.

Copy link
Author

Choose a reason for hiding this comment

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

I didn't find out which specific version it was fixed in, so I gave up trying to determine the version. :(

Copy link
Owner

Choose a reason for hiding this comment

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

Just test that on the version that it did not work before, we can print this warning, instead of fail.

def custom_capitalize(self):
print("custom capitalize")

t2 = ObjTest({"hex": custom_hex, "capitalize": custom_capitalize})
Copy link
Owner

Choose a reason for hiding this comment

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

I don't quite understand what we are testing here. This seems like a normal test case that should be covered by print_methods tests. I think simply keeping the test above would work. A regression test is to confirm something that does not work before works after the fix. We don't test something that does not change behavior with the change.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I will delete this case. I have some misunderstanding here.


t1 = b""
s = objstr(t1, print_methods=True, honor_existing=False)
self.assertIn("<signature unknown>", s)
Copy link
Owner

Choose a reason for hiding this comment

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

Is this passing in the latest version? Let's only test this for certain versions. You can add a skipIf or skipUnless. Did you say 3.13 has a different behavior?

Copy link
Author

Choose a reason for hiding this comment

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

OK, everythins is ok! It has been tested successfully in the latest version.
https://github.com/Lonely-Dream/objprint/actions/runs/13811688833

The previous version did not pass the test.
https://github.com/Lonely-Dream/objprint/actions/runs/13811661055

Copy link
Author

Choose a reason for hiding this comment

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

No different behavior.

Copy link
Owner

Choose a reason for hiding this comment

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

Interesting, so for all exsiting versions, the signature of the methods are not available.

Copy link

codecov bot commented Mar 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (89a9cf8) to head (252fbc8).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #121   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          374       378    +4     
=========================================
+ Hits           374       378    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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