diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 689be864f3..f8d216c9e7 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -423,3 +423,5 @@ contributors: * Joshua Cannon: contributor * Giuseppe Valente: contributor + +* cdce8p: contributor diff --git a/ChangeLog b/ChangeLog index d0ee2fed91..d42012a3f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,7 +19,7 @@ Release date: TBA * Fix bug that lead to duplicate messages when using ``--jobs 2`` or more. Close #3584 - + * Adds option ``check-protected-access-in-special-methods`` in the ClassChecker to activate/deactivate ``protected-access`` message emission for single underscore prefixed attribute in special methods. @@ -62,6 +62,8 @@ Release date: TBA * Fix minor documentation issues +* Fix false-positive ``unsubscriptable-object`` message for ``typing.Union`` and ``typing.Optional``. Closes #3882 + What's New in Pylint 2.6.0? =========================== diff --git a/doc/whatsnew/2.6.rst b/doc/whatsnew/2.6.rst index 56c60a5b97..b0f720aac6 100644 --- a/doc/whatsnew/2.6.rst +++ b/doc/whatsnew/2.6.rst @@ -52,3 +52,5 @@ Other Changes * Fix vulnerable regular expressions in ``pyreverse``. The ambiguities of vulnerable regular expressions are removed, making the repaired regular expressions safer and faster matching. .. _the migration guide in isort documentation: https://timothycrosley.github.io/isort/docs/upgrade_guides/5.0.0/#known_standard_library + +* Fix false-positive ``unsubscriptable-object`` message for ``typing.Union`` and ``typing.Optional``. Closes #3882 diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 23836f9097..5e845c9681 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -1076,6 +1076,9 @@ def _supports_protocol( return True if protocol_callback(value): return True + if isinstance(value, astroid.FunctionDef): + if value.name in ("Optional", "Union"): + return True if ( isinstance(value, _bases.Proxy)