Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n",
"#### SPDX-License-Identifier: Apache-2.0"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# {fact rule=notebook-variable-redefinition@v1.0 defects=0}\n",
"import math\t"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"x = int(input('x:'))\n",
"y = int(input('y:'))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"z = '5'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"z: 44.64302857109943\n"
]
}
],
"source": [
"# Compliant: Even though there are 2 different types assigned to variable `z` in two different cells, it is only used within one of the two cells.\n",
"z = math.sqrt(x**2 + y**2)\n",
"print ('z:', z)\n",
"# {/fact}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n",
"#### SPDX-License-Identifier: Apache-2.0"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# {fact rule=notebook-variable-redefinition@v1.0 defects=1}\n",
"import math"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"x = int(input('x:'))\n",
"y = int(input('y:'))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"z = '5'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"z = math.sqrt(x**2 + y**2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"z: 34.17601498127012\n"
]
}
],
"source": [
"# Noncompliant: variable `z` is assigned to 2 different types of values in above cells 3 and 4. \n",
"# Then in cell 5, the value of `z` is used in a `print()` call.\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then in cell 5, the value of z is used in a print() call, which can have different result depending on the execution order of cells. \n"

"print ('z:', z)\n",
"# {/fact}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}