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

Potential accidental capture of loop variable in Boxer #2918

Open
tomaarsen opened this issue Dec 18, 2021 · 1 comment · May be fixed by #3066
Open

Potential accidental capture of loop variable in Boxer #2918

tomaarsen opened this issue Dec 18, 2021 · 1 comment · May be fixed by #3066

Comments

@tomaarsen
Copy link
Member

tomaarsen commented Dec 18, 2021

Hello!

Within the last list comprehension in this return statement, the cond value will always take the value of the last element of conds:

nltk/nltk/sem/boxer.py

Lines 533 to 537 in 4a130f1

return [
lambda sent_index, word_indices: BoxerPred(
self.discourse_id, sent_index, word_indices, arg, tok, "n", 0
)
] + [lambda sent_index, word_indices: cond for cond in conds]

This seems like it would be unexpected or undesired behaviour.

For those unaware of what I'm talking about, a Python implementation detail causes the following:

int_list = [1, 2, 3, 4, 5]
functions = [
    lambda: print(i) 
    for i in int_list
]
for func in functions:
    func()

outputs

5
5
5
5
5

while one might expect

1
2
3
4
5

I don't have the time to look into this now, and I'm not sure if this affects many people, so that's why I'll just write it as an issue instead. This probably isn't the highest priority issue, by the way.

  • Tom Aarsen
@gokulnathselvaraj27
Copy link

i would like to contribute

gokul-the-dev pushed a commit to gokul-the-dev/nltk that referenced this issue Apr 29, 2022
@asishm asishm linked a pull request Nov 4, 2022 that will close this issue
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 a pull request may close this issue.

2 participants