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

Add compliant and noncompliant examples of python/[email protected] #80

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 [email protected] 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`, it is only used within the same cells.\n",

Choose a reason for hiding this comment

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

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.

"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 [email protected] 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
}