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

Allow star args in ctypes.Array constructor #6213

Merged
merged 4 commits into from Jan 22, 2019

Conversation

Projects
None yet
2 participants
@alanhdu
Copy link
Contributor

commented Jan 17, 2019

No description provided.

@ilevkivskyi
Copy link
Collaborator

left a comment

Thanks! PR looks good, I just have few suggestions for additional tests.

for arg_num, (arg_kind, arg_type) in enumerate(zip(ctx.arg_kinds[0], ctx.arg_types[0]), 1):
if arg_kind not in {nodes.ARG_POS, nodes.ARG_STAR}:
ctx.api.msg.fail(
"Array constructor does not allow keyword arguments",

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jan 17, 2019

Collaborator

Please add a test that triggers this error message.

This comment has been minimized.

Copy link
@alanhdu

alanhdu Jan 18, 2019

Author Contributor

It looks like this actually isn't ever called -- it looks like the constructor in typeshed def __init__(self, *args: Any) -> None) definition takes care of this case.

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jan 19, 2019

Collaborator

Oh, wait, so if it is never going to be called, maybe we can remove this code?

This comment has been minimized.

Copy link
@alanhdu

alanhdu Jan 22, 2019

Author Contributor

Done!

if not is_subtype(arg_type, ty):
ctx.api.msg.fail(
'Array constructor argument {} of type "{}"'
' is not convertible to the array element type "Iterable[{}]"'

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jan 17, 2019

Collaborator

Please also add a test for this error message.

@alanhdu alanhdu force-pushed the alanhdu:ctypes branch from 8b8471d to 3f5d045 Jan 18, 2019

[case testCtypesArrayConstructorKwargs]
import ctypes
intarr4 = ctypes.c_int * 4

This comment has been minimized.

Copy link
@alanhdu

alanhdu Jan 18, 2019

Author Contributor

I wanted to add a intarr4(1, 2, 3, x=4) test case here, but not sure how to get the tests to pass: the output on my machine is:

Expected:
  main:4: error: Unexpected keyword argument "x" for "Array"
  main:7: error: Too many arguments for "Array" (diff)
Actual:
  main:4: error: Unexpected keyword argument "x" for "Array"
  /home/alan/workspace/python/mypy/mypy/typeshed/stdlib/2and3/ctypes/__init__.pyi:273: note: "Array" defined here (diff)
  main:7: error: Too many arguments for "Array" (diff)

I added a # E: comment for the error, but don't know how to handle the note (which includes the path, so will be setup specific). Thoughts?

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Jan 19, 2019

Collaborator

Oh, this note caused some problems before. One option would be to add some very simple mock stubs to test-data/unit/lib-stub. But probably even better is just not add this test. The two tests you have added are sufficient.

@ilevkivskyi ilevkivskyi merged commit bbf0fd3 into python:master Jan 22, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@alanhdu alanhdu deleted the alanhdu:ctypes branch Jan 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.