Skip to content

Fix ResourceWarnings in tests#1660

Merged
menshikh-iv merged 1 commit into
piskvorky:developfrom
horpto:bugfix-ResourceWarning
Oct 31, 2017
Merged

Fix ResourceWarnings in tests#1660
menshikh-iv merged 1 commit into
piskvorky:developfrom
horpto:bugfix-ResourceWarning

Conversation

@horpto
Copy link
Copy Markdown
Contributor

@horpto horpto commented Oct 28, 2017

No description provided.

@horpto horpto force-pushed the bugfix-ResourceWarning branch from 1120982 to e2ff841 Compare October 28, 2017 18:54
Comment thread gensim/utils.py


@contextmanager
def file_or_filename(input):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see in usage, this function used as contextmanager, why you remove this (@contextmanager + yield) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it really doesn't work as was expected, nice catch!

Copy link
Copy Markdown
Contributor Author

@horpto horpto Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After meged comment:

Actually, it was already brokenl. Compare with code:

from contextlib import contextmanager

@contextmanager
def g():
    print("g input")
    yield
    print("g exit")

@contextmanager
def f():
    print("f input")
    yield g()
    print("f exit")


with f():
    print("with block")

This code prints:

f input
with block
f exit

But expected something like:

f input
g input
with block
g exit
f exit

Back to the file_or_filename, methods __enter__ and __exit__ of smart_open(input) or input are not called at all. Oops.

Comment thread gensim/matutils.py
if docid != previd:
if previd >= 0:
return document
break
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok. But I don't understand what exactly should I check in it ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read full method definition, now it's clear for me, thanks.

@menshikh-iv menshikh-iv merged commit d7190f3 into piskvorky:develop Oct 31, 2017
@horpto horpto deleted the bugfix-ResourceWarning branch November 7, 2017 11:50
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.

2 participants