pylint
pylint copied to clipboard
False positive: Various dict-access checks fail when using NewType for Dict[str,str]
Bug description
When using a NewType type definition based on Dict[str,str] and using regular dict-access methods, this generates various false positive warnings, e.g. unsupported-assignment-operation, unsubscriptable-object.
Sample code:
from typing import Dict
from typing import NewType
DatasetTags = NewType("DatasetTags", Dict[str,str])
test = DatasetTags({})
test['toast'] = 5
b = test['toast']
Possibly related issues: For Tuples: https://github.com/PyCQA/pylint/issues/4944 For Lists: https://github.com/PyCQA/pylint/issues/2296
Configuration
No response
Command used
pylint --disable=missing-docstring newtype_test.py
Pylint output
************* Module newtype_test
newtype_test.py:8:0: E1137: 'test' does not support item assignment (unsupported-assignment-operation)
newtype_test.py:9:4: E1136: Value 'test' is unsubscriptable (unsubscriptable-object)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Expected behavior
No issues should be reported, as the dict-access is correct.
Pylint version
pylint 2.14.5
astroid 2.11.7
Python 3.11.0b5 (main, Aug 17 2022, 10:25:57) [Clang 13.1.6 (clang-1316.0.21.2.3)]
OS / Environment
MacOS on M1 Mac (arm64-architecture)
Additional dependencies
No response
Thanks for the report. We could probably close all of the NewType issues as duplicates of #2296. We need astroid to know that NewType callables return instances of the parameter passed in.
Current NewType bugs afaik : #2296, #3162, #4944, #4961