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

move some stuffs related to _SimpleCData from ctypes/__init__.pyi to _ctypes.pyi, as at runtime. #10118

Merged
merged 3 commits into from
Apr 30, 2023

Conversation

junkmd
Copy link
Contributor

@junkmd junkmd commented Apr 30, 2023

related to #8633 and #8571 (comment)

#10111 and google/pytype#1411 (commit; google/pytype@2e2088f) have enabled us to move definitions from __init__.pyi to _ctypes.pyi.(#8633 (comment))
There are no longer causes CI to fail
So I'm going to contribute for the first time in several months.

I have moved the following stuffs.

  • _CDataMeta
  • _CData
  • _SimpleCData
  • Array

And I fixed stubtest_allowlist for _ctypes.Array.

junkmd and others added 3 commits April 30, 2023 21:59
@junkmd
Copy link
Contributor Author

junkmd commented Apr 30, 2023

Thank you for the correction in 727ceb8.

Copy link
Member

@AlexWaygood AlexWaygood 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!

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/pq/pq_ctypes.py:1026: error: Returning Any from function declared to return "bytes"  [no-any-return]

discord.py (https://github.com/Rapptz/discord.py)
- discord/opus.py:377: error: Value of type variable "_T" of "array" cannot be "bytes"  [type-var]

@AlexWaygood
Copy link
Member

Diff from mypy_primer, showing the effect of this PR on open source code:

psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/pq/pq_ctypes.py:1026: error: Returning Any from function declared to return "bytes"  [no-any-return]

discord.py (https://github.com/Rapptz/discord.py)
- discord/opus.py:377: error: Value of type variable "_T" of "array" cannot be "bytes"  [type-var]

It looks like this interferes slightly with mypy's plugin for typechecking ctypes code. There's a bunch of places in the mypy codebase where they hardcode if fullname == "ctypes.Array" etc.:

https://github.com/python/mypy/blob/6b1fc865902bf2b845d3c58b6b9973b5a412241f/mypy/plugins/default.py#L41-L48

It should be fairly easy to fix; I can make a PR to mypy.

@junkmd
Copy link
Contributor Author

junkmd commented Apr 30, 2023

It should be fairly easy to fix; I can make a PR to mypy.

Excellent. 👍

It would be very helpful to have you do this.

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 30, 2023

Hmm, actually, looks like it might not be possible to fix the mypy plugin (or might be pretty difficult to do so) unless it's done after mypy updates their vendored copy of typeshed following this change.

@hauntsaninja, do you reckon it's okay to merge this for now, and fix mypy after the next typeshed sync?

@hauntsaninja
Copy link
Collaborator

Yeah, that sounds good!

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.

3 participants