Skip to content

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

Merged
AlexWaygood merged 3 commits into
python:mainfrom
junkmd:move_ctypes_definitions_part1
Apr 30, 2023
Merged

AlexWaygood merged 3 commits into
python:mainfrom
junkmd:move_ctypes_definitions_part1

Conversation

@junkmd

@junkmd junkmd commented Apr 30, 2023

Copy link
Copy Markdown
Contributor

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

junkmd commented Apr 30, 2023

Copy link
Copy Markdown
Contributor Author

Thank you for the correction in 727ceb8.

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

junkmd commented Apr 30, 2023

Copy link
Copy Markdown
Contributor Author

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

AlexWaygood commented Apr 30, 2023 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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