forked from pylint-dev/pylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false positive
protected-access
in typing (pylint-dev#4937)
* Fix false positive ``protected-access`` in typing Class functions can return protected members which can then be passed as arguments to other functions. When using type hints in function definitions these raised a message which they shouldn't do.
- Loading branch information
1 parent
8b778cd
commit e1da3c0
Showing
7 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/functional/a/access/access_to_protected_members_typing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# pylint: disable=too-few-public-methods, invalid-name | ||
"""Test typing with a protected member""" | ||
from __future__ import annotations | ||
|
||
|
||
class MyClass: | ||
"""Class with protected members.""" | ||
|
||
class _Inner_Class: | ||
"""Inner class with protected members.""" | ||
|
||
def __init__(self) -> None: | ||
self.data = 1 | ||
|
||
def return_data(self) -> int: | ||
"""Return data""" | ||
return self.data | ||
|
||
def return_private_class(self) -> MyClass._Inner_Class: | ||
"""Doing nothing.""" | ||
return self._Inner_Class() | ||
|
||
|
||
def access_protected_class(data: MyClass._Inner_Class) -> int: | ||
"""Function that always receives a protected class.""" | ||
return data.return_data() + 1 | ||
|
||
|
||
def pass_protected_class() -> None: | ||
"""Function that passes a protected class to another function.""" | ||
data_value = access_protected_class(MyClass().return_private_class()) | ||
print(data_value) |
2 changes: 2 additions & 0 deletions
2
tests/functional/a/access/access_to_protected_members_typing.rc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[testoptions] | ||
min_pyver=3.7 |
Empty file.