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

Core.py removing 'type: ignore' hints #9197

Merged
merged 4 commits into from
May 26, 2023

Conversation

michael-gendy-mention-me
Copy link
Contributor

@michael-gendy-mention-me michael-gendy-mention-me commented May 24, 2023

As part of this issue, we want to remove some of the type: ignore hints to make the code more rigorous. This PR will aim to remove all the type: ignore hints in core.py

Comment on lines 85 to 91
pointers: ctypes.Array[ctypes.c_char_p] = (ctypes.c_char_p * len(data))()
data_as_bytes = [bytes(d, "utf-8") for d in data]
pointers[:] = data_as_bytes # type: ignore
data_as_bytes: List[bytes] = [bytes(d, "utf-8") for d in data]
pointers: ctypes.Array[ctypes.c_char_p] = (ctypes.c_char_p * len(data_as_bytes))(*data_as_bytes)
return pointers
raise TypeError()


Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is out of my wheelhouse somewhat, but to me it looks like we're initialising an empty ctypes.Array (pointers), then adding data_as_bytes to it which was creating a mismatch between the List[bytes] and ctypes.Array[ctypes.c_char_p]. I've just added the data_as_bytes into pointers at initialisation, does this make sense?

Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I don't quite understand it either. Need to look it up. ;-)

@michael-gendy-mention-me
Copy link
Contributor Author

Just committed the linting changes from https://github.com/dmlc/xgboost/actions/runs/5069030065/jobs/9121890991

Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you for removing the workarounds!

@trivialfis trivialfis merged commit c5677a2 into dmlc:master May 26, 2023
@michael-gendy-mention-me
Copy link
Contributor Author

Apologies I've been away for a number of days. Thanks a lot for the review, merge and help finding something to work on @trivialfis 😄

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