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

Function "filter" fails when the type of the first argument is not bool #241

Closed
xiaxinmeng opened this issue Mar 15, 2023 · 2 comments
Closed

Comments

@xiaxinmeng
Copy link

The function filter fails when the type of the first argument is not bool.

test.py

L = (4,9,3,14,7,10,6,1)
def is_odd(x):
    return x % 2 
newlist = list(filter(is_odd,L))
print(newlist)

Reproduce:
codon/codon-linux-x86_64/codon-deploy/bin/codon' run -release test.py

Crash message:

48793_1093447229__0.py:15:16-22: error: 'filter[is_odd[...],Generator[int],int]' does not match expected type 'filter[Callable[[int],bool],Generator[int],int]'
corrupted double-linked list
Aborted (core dumped)

Behavior on CPython 3.10.8:
[9, 3, 7, 1]

Environment:
codon: v0.15.5 on Feb 6
Ubuntu 18.04

@Michael-F-Ellis
Copy link

Python filter functions should return a bool. The following works as expected.

L = (4,9,3,14,7,10,6,1)
def is_odd(x):
    return x % 2 > 0
newlist = list(filter(is_odd,L))
print(newlist)

@inumanag
Copy link
Contributor

inumanag commented Nov 9, 2024

Crash is fixed in #604. Thank you @Michael-F-Ellis for the correct solution!

@inumanag inumanag closed this as completed Nov 9, 2024
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

No branches or pull requests

3 participants