This rule raises an issue when an item or attribute is assigned on an object whose type resolves to an immutable frozendict.

Why is this an issue?

A frozendict is immutable. Its items cannot change after it is created. Assigning an item or attribute to it will fail at runtime or does not represent a valid update to the mapping.

What is the potential impact?

The assignment can raise an exception at runtime and prevent the application from completing the intended operation.

How to fix it

Do not modify the immutable mapping. Read the existing value, or create a new mapping that contains the required change.

Code examples

Noncompliant code example

data: frozendict
data["key"] = "value"  # Noncompliant

Compliant solution

data: frozendict
value = data["key"]

updated_data = frozendict({**data, "key": "value"})

Resources

Documentation