Skip to content

Conversation

@lowzhao
Copy link
Contributor

@lowzhao lowzhao commented Nov 7, 2025

Type of Changes

Type
βœ“ πŸ› Bug fix
✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

Getting the lineno of the start of the block for function definition(FunctionDef.blockstart_tolineno) can be quite tricky. Take below example:

# 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

The function definition can be quite tricky. Take below example:

```
# Case A
def foo(bar: str) -> None: 
    pass

# Case B
def foo(
    bar:str ): 
    pass

# Case C
def foo(
    bar:str
) -> None: 
    pass

# Case D
def foo(
    bar:str
): 
    pass
```

Currently we only handled Case A, B. With this commit we can cover case C, but not Case D.
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening a PR, do you mind adding automated test for this, please ?

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 93.31%. Comparing base (ff7205c) to head (b935c77).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2880      +/-   ##
==========================================
+ Coverage   93.30%   93.31%   +0.01%     
==========================================
  Files          92       92              
  Lines       11194    11196       +2     
==========================================
+ Hits        10445    10448       +3     
+ Misses        749      748       -1     
Flag Coverage Ξ”
linux 93.18% <100.00%> (+0.01%) ⬆️
pypy 93.31% <100.00%> (+0.01%) ⬆️
windows 93.30% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Ξ”
astroid/nodes/scoped_nodes/scoped_nodes.py 93.70% <100.00%> (+0.08%) ⬆️
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Added 4 test cases to test different argument and return statement lineno, also with or without annotations.
Add another test case for FunctionDef's blockstart_tolineno, which without annotations will still work.
@lowzhao
Copy link
Contributor Author

lowzhao commented Nov 7, 2025

Thank you for opening a PR, do you mind adding automated test for this, please ?

Sure! I have added some test cases. Sorry for making some amends, should be good now :)

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just waiting for the coverage job to show up :)

@Pierre-Sassoulas Pierre-Sassoulas merged commit 8fa18c7 into pylint-dev:main Nov 8, 2025
19 checks passed
pylint-backport bot pushed a commit that referenced this pull request Nov 8, 2025
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)
@Pierre-Sassoulas
Copy link
Member

Great first contribution to astroid !

Pierre-Sassoulas pushed a commit that referenced this pull request Nov 8, 2025
…dge 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 <lowzhao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants