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 memoryview type checking issue #5988

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cython/Compiler/PyrexTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ def type_check_function(self, exact=True):
type_check = "PyMemoryView_Check"
else:
type_check = 'Py%s_Check' % type_name.capitalize()
if exact and type_name not in ('bool', 'slice', 'Exception'):
if exact and type_name not in ('bool', 'slice', 'Exception', 'memoryview'):
type_check += 'Exact'
return type_check

Expand Down
15 changes: 14 additions & 1 deletion tests/run/builtin_memory_view.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import print_function

import sys
import io
XeniaLu marked this conversation as resolved.
Show resolved Hide resolved

cimport cython
#from cpython.memoryview cimport PyMemoryView_GET_BUFFER
Expand Down Expand Up @@ -59,3 +59,16 @@ def test_in_with(x):
"""
with memoryview(x) as xv:
print(xv[1])


def test_returned_type():
"""
This is really just a compile test. An optimization was being
applied in a way that generated invalid code
>>> test_returned_type()
98
"""
def foo() -> memoryview:
return io.BytesIO(b"abc").getbuffer()
XeniaLu marked this conversation as resolved.
Show resolved Hide resolved

print(foo()[1])