Reasons
Represents a function and the raw reasons for impurity.
Raw reasons means that the reasons are just collected and not yet processed.
Attributes:
| Name | Type | Description |
|---|---|---|
function_scope |
FunctionScope | None
|
The scope of the function which the reasons belong to. Is None if the reasons are not for a FunctionDef node. This is the case when either a builtin or a combined node is created, or a ClassScope is used to propagate reasons. |
writes_to |
dict[NodeID, NonLocalVariableWrite]
|
A dict of all nodes that are written to. |
reads_from |
dict[NodeID, NonLocalVariableRead]
|
A dict of all nodes that are read from. |
calls |
set[Symbol]
|
A set of all nodes that are called. |
result |
PurityResult | None
|
The result of the purity analysis This also works as a flag to determine if the purity analysis has already been performed: If it is None, the purity analysis has not been performed |
unknown_calls |
dict[NodeID, UnknownProto]
|
A dict of all unknown calls. Unknown calls are calls to functions that are not defined in the module or are parameters. |
Source code in src/library_analyzer/processing/api/purity_analysis/model/_reference.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
calls: set[Symbol] = field(default_factory=set)
class-attribute
instance-attribute
¶
function_scope: FunctionScope | None = field(default=None)
class-attribute
instance-attribute
¶
id: NodeID
instance-attribute
¶
reads_from: dict[NodeID, NonLocalVariableRead] = field(default_factory=dict)
class-attribute
instance-attribute
¶
result: PurityResult | None = field(default=None)
class-attribute
instance-attribute
¶
unknown_calls: dict[NodeID, UnknownProto] = field(default_factory=dict)
class-attribute
instance-attribute
¶
writes_to: dict[NodeID, NonLocalVariableWrite] = field(default_factory=dict)
class-attribute
instance-attribute
¶
__init__(id, function_scope=None, writes_to=dict(), reads_from=dict(), calls=set(), result=None, unknown_calls=dict())
¶
join_reasons(other)
¶
Join two Reasons objects.
When a function has multiple reasons for impurity, the Reasons objects are joined. This means that the writes, reads, calls and unknown_calls are merged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
Reasons
|
The other Reasons object. |
required |
Returns:
| Type | Description |
|---|---|
Reasons
|
The updated Reasons object. |
Source code in src/library_analyzer/processing/api/purity_analysis/model/_reference.py
join_reasons_list(reasons_list)
¶
Join a list of Reasons objects.
Combines a list of Reasons objects into one Reasons object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reasons_list |
list[Reasons]
|
The list of Reasons objects. |
required |
Returns:
| Type | Description |
|---|---|
Reasons
|
The combined Reasons object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the list of Reasons objects is empty. |