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
Final py3.9 deprecation #2801
Final py3.9 deprecation #2801
Conversation
@@ -37,32 +37,30 @@ | |||
###################################################################### | |||
|
|||
|
|||
def usage(obj, selfname="self"): | |||
def usage(obj): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could alternatively delete this method? it's only used in nltk/test/classify.doctest
and that usage feels unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unaware of this function, but I could definitely see how it has a nice educatory use. Being able to quickly see the useful methods of a class can be quite useful if you're not entirely aware of the codebase, especially considering that NLTK is definitely not as well documented as I'd like.
There are some classes in NLTK for which users definitely might like to get an overview of the methods that it supports. nltk.tree.Tree
, nltk.BigramCollocationFinder
and nltk.FreqDist
come to mind, but upon trying the last one, I get the following exception:
>>> import nltk
>>> nltk.usage(nltk.FreqDist)
FreqDist supports the following operations:
- self.B()
- self.N()
- self.Nr(r, bins=None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[sic]\nltk\util.py", line 53, in usage
signature = inspect.signature(method)
File "[sic]\lib\inspect.py", line 3130, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "[sic]\lib\inspect.py", line 2879, in from_callable
return _signature_from_callable(obj, sigcls=cls,
File "[sic]\lib\inspect.py", line 2334, in _signature_from_callable
return _signature_from_builtin(sigcls, obj,
File "[sic]\lib\inspect.py", line 2145, in _signature_from_builtin
raise ValueError("no signature found for builtin {!r}".format(func))
ValueError: no signature found for builtin <method 'clear' of 'dict' objects>
Potentially this is because FreqDist
subclasses collections' Counter
, which again subclasses dict
. Note that I also got a similar exception before this PR.
As far as I'm concerned, this can still be merged, as the bug existed before this already regardless. We can just open an issue for it then. However, if you feel like it, you can also include a fix for this in this PR already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!! you're totally right, thanks!
turns out that inspect
and some builtin functions don't always work out together. i can't really figure out how to get the failing ones working, my best workaround is to skip them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what about Python's built-in help
command? It gives you both methods and attributes as well as their docstrings. I use it extensively with all kinds of codebases.
I completely agree that the docs need some love, but that's a separate issue imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's indeed a separate issue I'd say.
I'd even consider usage
failing on some builtin functions to be a separate issue. If you'd like to get this merged, then we can just open an issue saying that usage
is broken in some cases. That is, assuming that the bug still exists.
Regarding the tests, it might be a good idea to check if the output .startswith("MyClass supports the following operations:")
or something, or whether the output is indeed a string with at least length ~35 or something. It's not much, but then at least we have some tests to verify that it prints a string with "... supports the following operations: ..."
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's just treat that as a separate issue.
cf38004
to
a64ac96
Compare
Thanks @dannysepler, @tomaarsen, @iliakur |
Closes #2689. All the other deprecations have been taken care of here #2698
This also added a few tests (and snuck in a pytest refactor)