-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
symtable.Class.get_methods() returns non-methods #119698
Comments
The
shows details:
We see that We can simply deprecate |
I have never used this module and I don't know how people are using it; I ran into this problem because some tests failed while I was working on the PEP 649 implementation. Deprecating this method seems like a reasonable path forward. |
cc @picnixz in case you're interested in other problems with the symtable module. |
Personally, I've never used it but I was interested in contributing to CPython so I started where I thought it was something not too hard and interesting. One use case that I have in mind is IntelliSense but I would expect those tools to actually use the AST instead (but since their code is private, I cannot say for sure). If there is really no use-case, I'd suggest deprecating it (less things to maintain, easier for us). I've tried to search whether it's used or not on github but I've only seen this occurrence https://github.com/skulpt/skulpt/blob/8daae6db0d2834ae2e66f6407e00239d4a95ead1/skulpt.py#L101 being relevant (others are not I think). However, they are using the thing for Python 2 and are not claiming full Python 3 compatibility. |
I decided to keep the PR fixing the interface since Carl and Jelle have reviewed it and the work was not that much. |
For the record, I've implemented Note that the branch actually contains a local copy of #120151 (and I will not open a PR yet). |
I would only add such methods if someone comes up with an actual use case. |
I only have found the use of this method in the skulpt project, which is Python 2 only. I also prefer to deprecate it. |
To summarize, we would fix the method in 3.14 (and 3.12, 3.13, depending on the backport decision), deprecate it in 3.15 and remove it in 3.17? (and it's fine that we don't need the other methods) |
Why not deprecate it in 3.14? |
Err..., maybe someone will be interested in using it since we fixed it? (I can add the deprecation in the same or a follow-up PR though) |
We should definitely do only one of deprecating and fixing, not both; it doesn't make sense to radically change the implementation of the method and then immediately deprecate it. I would prefer to fix the method instead of deprecating it though. We have a solution that fixes the method (#120151), and I don't think maintaining the method in the future will be very costly. I think we should only deprecate the method if there's some strong reason we don't want it in the library in the future. |
If we are going to fix Note that currently functions which return a limited set of names, such as |
…r correctly (#120151) Co-authored-by: Jelle Zijlstra <[email protected]>
…haviour correctly (python#120151) Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit b8a8e04)
… its behaviour correctly (pythonGH-120151) (cherry picked from commit b8a8e04) Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
… its behaviour correctly (pythonGH-120151) (cherry picked from commit b8a8e04) Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
…ehaviour correctly (#120151) (#120776) (cherry picked from commit b8a8e04) Co-authored-by: Bénédikt Tran <[email protected]>
…ehaviour correctly (GH-120151) (#120777) (cherry picked from commit b8a8e04) Co-authored-by: Bénédikt Tran <[email protected]>
…haviour correctly (python#120151) Co-authored-by: Jelle Zijlstra <[email protected]>
I still prefer to deprecate this method. But it is fine if other core developers need it. |
I'm not strongly opposed to deprecating the method, but we now have a fixed implementation and I don't foresee the method causing a lot of problems in the future, so I don't see a strong cause for inconveniencing users by deprecating it. |
It is pretty complex now, with complex tests and documentation, and I am not even sure that it is correct. It has high maintenance cost, and its usefulness is questionable. Actually, I just found a bug in it: |
import symtable
st = symtable.symtable("""
class X:
x = (x for x in range(10))
genexpr = 1
""", '?', 'exec')
cls = st.get_children()[0]
print(cls.get_methods()) (For some reasons Firefox crashed on my computer when paste from clipboard. After updating it this was fixed.) |
Ah I think I forgot that case where a symbol is called 'genexpr'. Actually, I also have this issue: import symtable
st = symtable.symtable("""
class X:
genexpr = (x for x in range(10))
""", '?', 'exec')
cls = st.get_children()[0]
print(cls.get_methods()) Ideally, if we could rename 'genexpr' by '.genexpr', it could make the name special. Because otherwise the following 'genexpr' would not be picked up... (I cannot just say that the identifier is invalid, for 'lambda' I can since it's a keyword but not for 'genexpr'). class X:
def genexpr(): pass |
…haviour correctly (python#120151) Co-authored-by: Jelle Zijlstra <[email protected]>
Re-opening until the fix of the fix (+backports) lands and the deprecation notice is merged. |
…haviour correctly (python#120151) Co-authored-by: Jelle Zijlstra <[email protected]>
…ythonGH-121802) (cherry picked from commit 6682d91) Co-authored-by: Bénédikt Tran <[email protected]>
…ythonGH-121802) (cherry picked from commit 6682d91) Co-authored-by: Bénédikt Tran <[email protected]>
…H-121802) (#121909) (cherry picked from commit 6682d91) Co-authored-by: Bénédikt Tran <[email protected]>
I opened also #121914. |
…H-121802) (#121910) (cherry picked from commit 6682d91) Co-authored-by: Bénédikt Tran <[email protected]>
Bug report
Bug description:
Running this file:
Prints:
None of these are methods.
@carljm and I noticed this as part of the work on PEP 649 (#119361 (comment)). My draft implementation excludes generated
__annotate__
functions from the list of "methods", but perhaps all non-methods should be excluded.CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
macOS
Linked PRs
symtable.Class.get_methods
#120148symtable.Class.get_methods
and document its behaviour correctly #120151symtable.Class.get_methods
and document its behaviour correctly (#120151) #120776symtable.Class.get_methods
and document its behaviour correctly (GH-120151) #120777symtable.Class.get_methods
#121802symtable.Class.get_methods
#121902symtable.Class.get_methods
(GH-121802) #121909symtable.Class.get_methods
(GH-121802) #121910The text was updated successfully, but these errors were encountered: