Re: Issue 374 in nltk: decorators.py bug

51 views
Skip to first unread message

nl...@googlecode.com

unread,
Jun 4, 2010, 10:58:37 PM6/4/10
to nltk-...@googlegroups.com
Updates:
Labels: Component-util

Comment #1 on issue 374 by StevenBird1: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

(No comment was entered for this change.)

nl...@googlecode.com

unread,
Nov 16, 2010, 10:56:37 PM11/16/10
to nltk-...@googlegroups.com

Comment #2 on issue 374 by alex.rudnick: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

I think what causes this is that, when decorators.py imports "inspect",
inspect then imports "tokenize".

But when you're in this directory, "tokenize" refers to NLTK's tokenize,
not Python's tokenize.

I the error go away by temporarily removing NLTK's tokenize directory. Is
there a way to make sure that NLTK's tokenize doesn't conflict with Python
standard library code trying to import Python's "tokenize", short of
renaming the NLTK module?

nl...@googlecode.com

unread,
Nov 17, 2010, 8:30:22 PM11/17/10
to nltk-...@googlegroups.com

Comment #3 on issue 374 by StevenBird1: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

I agree with this diagnosis. I wonder why "import tokenize" inside the
inspect module finds nltk.tokenize. Perhaps this is a case of implicit
relative imports. How can we avoid this?
http://docs.python.org/tutorial/modules.html#intra-package-references


nl...@googlecode.com

unread,
Nov 17, 2010, 11:36:27 PM11/17/10
to nltk-...@googlegroups.com

Comment #4 on issue 374 by alex.rudnick: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

It can be fixed with a pretty simple hack that takes out the "nltk"
directory from sys.path before we try to import "tokenize".

Is this too ham-fisted? (if it's OK, I'll go ahead and check it in.)

Attachments:
fix_decorators_r8704.patch 564 bytes

nl...@googlecode.com

unread,
Nov 18, 2010, 4:48:11 AM11/18/10
to nltk-...@googlegroups.com

Comment #5 on issue 374 by StevenBird1: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

Does this work? I think the inspect module picks up nltk.tokenize via the
implicit relative import mechanism: "the import statement first looks in
the containing package before looking in the standard module search path".
Removing nltk from sys.path should have no effect on "import tokenize", but
only on "from nltk import tokenize" and on "import nltk.tokenize".

nl...@googlecode.com

unread,
Nov 18, 2010, 11:59:48 AM11/18/10
to nltk-...@googlegroups.com

Comment #6 on issue 374 by alex.rudnick: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

It does work; and I think you're right about the implicit relative import
being why nltk's tokenize gets picked up.

It's just that when you execute python nltk/decorators.py, the nltk
directory is now in the module path. Printing out sys.path before changing
it (for me) gives...

path:
['/home/alex/checkouts/nltk-trunk/nltk/nltk', '/usr/lib/python2.6', ...]

That first entry is the location of decorators.py.

nl...@googlecode.com

unread,
Nov 18, 2010, 3:54:32 PM11/18/10
to nltk-...@googlegroups.com

Comment #7 on issue 374 by StevenBird1: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

I see. Alright please go ahead and apply that patch and close this issue,
thanks.


nl...@googlecode.com

unread,
Nov 18, 2010, 4:10:50 PM11/18/10
to nltk-...@googlegroups.com
Updates:
Status: Fixed

Comment #8 on issue 374 by alex.rudnick: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

OK, committed the patch at r8706.

Thanks for taking a look, Steven!

nl...@googlecode.com

unread,
Dec 15, 2013, 7:45:17 PM12/15/13
to nltk-...@googlegroups.com

Comment #9 on issue 374 by taylorca...@gmail.com: decorators.py bug
http://code.google.com/p/nltk/issues/detail?id=374

FYI: The "if inspect.isclass(caller):" line still causes a problem if you
have a program called inspect.py in the same directory as the program being
run (_extract.py in the case below):

Traceback (most recent call last):
File "/home/.../_extract.py", line 6, in <module>
import nltk

File "/usr/local/lib/python2.7/dist-packages/nltk-3.0a3-py2.7.egg/nltk/__init__.py",
line 104, in <module>
from nltk.decorators import decorator, memoize

File "/usr/local/lib/python2.7/dist-packages/nltk-3.0a3-py2.7.egg/nltk/decorators.py",
line 183, in <module>
@decorator

File "/usr/local/lib/python2.7/dist-packages/nltk-3.0a3-py2.7.egg/nltk/decorators.py",
line 161, in decorator
if inspect.isclass(caller):
AttributeError: 'module' object has no attribute 'isclass'

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages