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 best_base to select proper base class #5324

Merged
merged 7 commits into from
May 19, 2024

Conversation

Snowapril
Copy link
Contributor

This revision implements itemsize slots and fix best_base implementation to select proper base class when generating class.

@@ -392,8 +392,6 @@ def test(i, format_spec, result):
test(123456, "1=20", '11111111111111123456')
test(123456, "*=20", '**************123456')

@unittest.expectedFailure
@run_with_locale('LC_NUMERIC', 'en_US.UTF8')
Copy link
Member

Choose a reason for hiding this comment

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

This line is not expected to be removed.

@@ -326,7 +326,8 @@ impl PyInt {

#[pyclass(
flags(BASETYPE),
with(PyRef, Comparable, Hashable, Constructor, AsNumber, Representable)
with(PyRef, Comparable, Hashable, Constructor, AsNumber, Representable),
itemsize(BigInt)
Copy link
Member

Choose a reason for hiding this comment

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

I don't get how this is intended to be used yet. How to handle it if it requires multiple fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not intended for multiple types to be declared with itemsize.
In the pyclass code, if the number of types declared with itemsize is not one, it is planned to raise an error in a way that developers can understand. Unlike basicsize, it seems difficult to automatically infer item type for each class delcaration, so I have chosen this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. I think itemsize implementation is better to be moved to other PRs. It seems it does not cause wrong behavior in best_base.

@Snowapril Snowapril force-pushed the best_base branch 2 times, most recently from 0964777 to d3e7b31 Compare May 18, 2024 08:44
@Snowapril Snowapril marked this pull request as ready for review May 18, 2024 09:04
@Snowapril
Copy link
Contributor Author

I can't reproduce test_types::test_int__format__locale failure in WSL ubuntu 22.04. It also seems not related to this PR. . 😂

Comment on lines 424 to 425
if sys.platform != "darwin":
test_int__format__locale = unittest.expectedFailure(test_int__format__locale)
Copy link
Member

Choose a reason for hiding this comment

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

Reverting this will fix the failing test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my.. That code accidentally got included in the commit. I've fixed it!

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

Thank you!

Comment on lines +1375 to +1376
debug_assert!(base.is_some());
Ok(base.unwrap())
Copy link
Member

Choose a reason for hiding this comment

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

unwrap implies panic!. So debug_assert! is duplication.

Suggested change
debug_assert!(base.is_some());
Ok(base.unwrap())
Ok(base.expect("best_base must exist"))

@youknowone youknowone merged commit aa0353a into RustPython:main May 19, 2024
11 checks passed
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.

None yet

2 participants