Commit d71bfac
[Backport maintenance/4.0.x] Handle FunctionDef blockstart_tolineno edge cases (#2881)
Handle FunctionDef blockstart_tolineno edge cases (#2880)
Getting the lineno of the start of the block for function definition(`FunctionDef.blockstart_tolineno`) can be quite tricky. Take below example:
```python
# Case A
def foo(bar: str) -> None:
pass
# should returns line=1
# Case B
def foo(
bar:str):
pass
# should returns line=2
# Case C
def foo(
bar:str
) -> None:
pass
# should returns line=3
# Case D
def foo(
bar:str
):
# should returns line=3
pass
```
Currently we only handled Case A, B. With this commit we can cover case C.
But for Case D, we will need a better solution
(cherry picked from commit 8fa18c7)
Co-authored-by: Low, Zhi Hao <[email protected]>1 parent e127630 commit d71bfac
File tree
2 files changed
+42
-0
lines changed- astroid/nodes/scoped_nodes
- tests
2 files changed
+42
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1401 | 1401 | | |
1402 | 1402 | | |
1403 | 1403 | | |
| 1404 | + | |
| 1405 | + | |
1404 | 1406 | | |
1405 | 1407 | | |
1406 | 1408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
982 | 982 | | |
983 | 983 | | |
984 | 984 | | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
985 | 1025 | | |
986 | 1026 | | |
987 | 1027 | | |
| |||
0 commit comments