Skip to content
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

False positive: Various dict-access checks fail when using NewType for Dict[str,str] #7474

Open
JonathanRohland-TNG opened this issue Sep 16, 2022 · 2 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@JonathanRohland-TNG
Copy link

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: #4944
For Lists: #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

@JonathanRohland-TNG JonathanRohland-TNG added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 16, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 16, 2022
@jacobtylerwalls
Copy link
Member

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.

@jacobtylerwalls jacobtylerwalls added the Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) label Sep 16, 2022
@Pierre-Sassoulas
Copy link
Member

Current NewType bugs afaik : #2296, #3162, #4944, #4961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants