ipython / ipython/ipykernel

Inspection of arguments in function cause inspection of surrounding function

Đang mở
#1,147 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
734
Fork
412
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
8

Mô tả

At the moment inspection of arguments in function calls is not possible as the function is inspected instead. This is because `do_inspect` relies on `IPython.utils.tokenutil.generate_tokens`:

https://github.com/ipython/ipykernel/blob/c24b252dc4fc81e6cf6354f8d64ea06ed1ce3496/ipykernel/ipkernel.py#L544-L546

The behaviour of `generate_tokens` has changed in https://github.com/ipython/ipython/commit/240eef90ab769a25100eb9f2c4247d775e6c160c . Before it would return the tokens of names, including parameters and names, even if they were inside a function call. Not all edge cases were handled correctly, but for most day-to-day inspection tasks were served fine. Now `generate_tokens` returns function names if the cursor is positioned inside the parentheses:

```
from IPython.utils.tokenutil import generate_tokens, token_at_cursor
from io import StringIO
code = 'func(param1, param2=arg)'
tokens = list(generate_tokens(StringIO(code).readline))

pos = dict(func=3, param1=8, param2=15, arg=22)
# Current behaviour
dict((k, token_at_cursor(code, v) for k, v in pos.items())
# Output: {'func': 'func', 'param1': 'func', 'param2': 'func', 'arg': 'func'}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start in ipykernel/ipkernel.py around lines 544-546 and inspect how do_inspect uses generate_tokens, token_at_cursor, and the surrounding cursor handling. Reproduce the provided func(param1, param2=arg) example, then verify that cursors on arguments identify those arguments rather than the surrounding function.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.