Skip to content

False negative assigned-from-none for value = dict.update({}, {}) #8714

@jamesbraza

Description

@jamesbraza

Current problem

This mistake recently bit a coworker of mine:

some_dict = {0: 1}.update({2: 3})
# This will fail, as `some_dict` is actually `None`
assert isinstance(some_dict, dict)

Obviously this type of error one should catch in unit testing, but we didn't have tests. mypy can catch this only if one adds type annotations.

I am wondering, can pylint catch this in the future, without type annotations?

Desired solution

pylint would:

  1. Understand that some_dict is actually None
  2. Know that its usage downstream as a dict will fail

In other words the request: pylint catching errors associated with None returns later being used as if not None.

Additional context

No response

Metadata

Metadata

Labels

False Negative 🦋No message is emitted but something is wrong with the codeHelp wanted 🙏Outside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions