-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Python 3.9] Value 'Optional' is unsubscriptable (unsubscriptable-object) (also Union) #3882
Comments
Also encountering this with the |
have updated the issue to cover interestingly, it doesn't seem to be a problem for some other types that use the subscript syntax, eg baz: List[int] = [1, 2, 3] # this is fine. |
This is definitely a false positive, the docs haven't changed: https://docs.python.org/3/library/typing.html#typing.Optional |
Self-contained reproducer, which is not Python 3.9 dependent (but the typing issue is 3.9 dependent): class deco:
def __init__(self, f):
self.f = f
def __getitem__(self, item):
return item
@deco
def Optional():
pass
print(Optional[int]) Probably related to #2578:
Looks like some code give up checks if the function is decorated, IIRC: if isinstance(owner, astroid.FunctionDef) and owner.decorators:
return False it would be a simple quick-fix if we have no good way of studying the decorator from now. As my reproducer is not 3.9 specific I'm digging about why the initial reproducer is failing on 3.9:
Optional in 3.8 is declared as: Optional = _SpecialForm('Optional', doc=...) while in 3.9 it's declared as: @_SpecialForm
def Optional(self, parameters):
... As pylint does not resolve decorator, the inference is still OK in 3.8 (no decorator) but fails in 3.9 (decorated). Looks like it could be fixed by using something like:
in visit_subscript in typecheck.py. |
Pylint does not support python 3.9 properly: Value 'Optional' is unsubscriptable (unsubscriptable-object) This is a known issue. Until it is fixed run the lint checks with python 3.8. Link: pylint-dev/pylint#3882 Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Thanks to all for your reports. I'm not sure the issue illustrated by @JulienPalard is the same as the original one. |
Pylint does not support python 3.9 properly: Value 'Optional' is unsubscriptable (unsubscriptable-object) This is a known issue. Until it is fixed run the lint checks with python 3.8. Link: pylint-dev/pylint#3882 Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
When run with Python 3.9, pylint incorrectly warns about things like Optional[foo] because it doesn't recognise Optional as unsubscriptable. This is a known pylint bug: pylint-dev/pylint#3882 Just disable this check to get rid of the warnings. Disabling this shouldn't make us miss any real bug because mypy also has a similar check ("... is not indexable"). Signed-off-by: Kevin Wolf <kwolf@redhat.com>
When run with Python 3.9, pylint incorrectly warns about things like Optional[foo] because it doesn't recognise Optional as unsubscriptable. This is a known pylint bug: pylint-dev/pylint#3882 Just disable this check to get rid of the warnings. Disabling this shouldn't make us miss any real bug because mypy also has a similar check ("... is not indexable"). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20201027163806.290960-3-kwolf@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Manually disabling spurious error message arising from a bug in pylint for Python 3.9, i.e., ``` pylint...............................................................................Failed - hook id: pylint - exit code: 2 -------------------------------------------------------------------- Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00) ************* Module structlog_sentry_logger._config structlog_sentry_logger/_config.py:240:18: E1136: Value 'Union' is unsubscriptable (unsubscriptable-object) ------------------------------------------------------------------ Your code has been rated at 9.52/10 (previous run: 9.52/10, +0.00) -------------------------------------------------------------------- Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00) -------------------------------------------------------------------- Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00) ``` see: [[Python 3.9] Value 'Optional' is unsubscriptable (unsubscriptable-object) (also Union) #3882](pylint-dev/pylint#3882)
This fixes false positive errors for Python 3.9. See pylint-dev/pylint#3882
This avoids a Pylint bug¹ that prevents adding a --errors-only check that would fail the build on failure. ¹ pylint-dev/pylint#3882
This solves a E1136 false positive with Python 3.9 [1], but the code needs some changes to test clean. [1] pylint-dev/pylint#3882
This solves a E1136 false positive with Python 3.9 [1], but the code needs some changes to test clean. [1] pylint-dev/pylint#3882
The pylint bug has been fixed (pylint-dev/pylint#3882)
Until pylint is fixed, unsubscriptable-object generates lots of false positives. This commit can be reverted with pylint > 2.6.0. See pylint-dev/pylint#3882
…tives caused by Optional fields in PlayerPair initialized to None. See pylint-dev/pylint#3882.
Just to fix this issue: pylint-dev/pylint#3882
The current version of pylint is 2 years old at this point, and it's got a bug (pylint-dev/pylint#3882) which is leading to false positives on ncs_west_helpers.py: E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:78 Column:36 E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:326 Column:18 E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:78 Column:36 E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:326 Column:18 E1136:Value 'Optional' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/pygit2_helpers.py Line:188 Column:46 E1136:Value 'Optional' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_commands.py Line:44 Column:38 Update it to the latest version. We have to update astroid, typing-extensions, and colorama as well as a side effect. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The current version of pylint is 2 years old at this point, and it's got a bug (pylint-dev/pylint#3882) which is leading to false positives on ncs_west_helpers.py: E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:78 Column:36 E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:326 Column:18 E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:78 Column:36 E1136:Value 'Union' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_west_helpers.py Line:326 Column:18 E1136:Value 'Optional' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/pygit2_helpers.py Line:188 Column:46 E1136:Value 'Optional' is unsubscriptable (unsubscriptable-object) File:scripts/west_commands/ncs_commands.py Line:44 Column:38 Update it to the latest version. We have to update astroid, typing-extensions, and colorama as well as a side effect. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Python 3.9 still fails, see pylint-dev/pylint#3882
Steps to reproduce
Install Python 3.9, then:
Current behavior
Pylint reports
Expected behavior
This isn't an error in Python 3.8 so I don't think it should be an error in 3.9?
pylint --version output
(I tried
pip install pylint astroid --pre -U
)The text was updated successfully, but these errors were encountered: