Skip to content
Open
Changes from all 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
129 changes: 129 additions & 0 deletions hello11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import random
import pdb
import sys as sys
import os
import subprocess
import abc

# from django.db.models.expressions import RawSQL

AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2"


class BaseNumberGenerator:
"""Declare a method -- `get_number`."""

def __init__(self):
self.limits = (1, 10)

def get_number(self, min_max):
raise NotImplemented

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`raise NotImplemented` throws `TypeError` unexpectedly


BaseNumberGenerator.get_number raises NotImplemented, which is invalid for raise. This causes confusing TypeError behavior and obscures contract violations.

Replace with raise NotImplementedError() to signal unimplemented abstract behavior correctly.


def smethod():
"""static method-to-be"""

smethod = staticmethod(smethod)

def cmethod(cls, something):
"""class method-to-be"""

cmethod = classmethod(cmethod)


class RandomNumberGenerator:
"""Generate random numbers."""

def limits(self):
return self.limits

def get_number(self, min_max=[1, 10]):
"""Get a random number between min and max."""
assert all([isinstance(i, int) for i in min_max])
return random.randint(*min_max)


def main(options: dict = {}) -> str:
pdb.set_trace()
if "run" in options:
value = options["run"]
else:
value = "default_value"

if type(value) != str:
raise Exception()
else:
value = iter(value)

sorted(value, key=lambda k: len(k))

f = open("/tmp/.deepsource.toml", "r")
f.write("config file.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Writing to file opened without write mode causes IOError


The f.write("config file.") operation is performed on a file that is likely opened without a write mode (w, a, or x). This causes an IOError since write operations require appropriate file opening modes. This prevents the file content from being updated as intended.

Open the file using a write mode like w to allow f.write() to succeed without errors and properly update file contents.

f.close()


def moon_chooser(moon, moons=["europa", "callisto", "phobos"]):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mutable default `moons` list causes shared state bugs


Using a mutable default value like the list assigned to the moons parameter means the same list object is reused on every function call. This can cause unexpected side effects when the list is modified, as changes persist across calls and affect all usages.

Replace the default list with None and inside the function assign a new list if the argument is None. This approach isolates each call with its own fresh list, avoiding shared state issues.

if moon is not None:
moons.append(moon)

return random.choice(moons)


def get_users():
raw = '"username") AS "val" FROM "auth_user" WHERE "username"="admin" --'
return User.objects.annotate(val=RawSQL(raw, []))


def tar_something():
os.tempnam("dir1")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `os.tempnam()` allows symlink attack vulnerabilities


The code calls os.tempnam("dir1"), which generates a temporary filename vulnerable to symlink attacks. An attacker could replace the file with a symbolic link, leading to unauthorized file modification or data leaks.
Replace os.tempnam() with os.tmpfile() or the tempfile module which securely creates temporary files preventing symlink race conditions.

subprocess.Popen("/bin/chown *", shell=True)
o.system("/bin/tar xvzf *")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Undefined `o` variable causes runtime error


The variable o is used to call system but is never defined or imported, which results in a runtime error preventing the command from executing. This stops the intended extraction operation from running properly.
Define or import the variable o properly before using it, commonly this is the os module for system calls or another appropriate context object.



def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz):
if (
initial_condition
and (
isinstance(object, int)
or isinstance(object, float)
or isinstance(object, str)
)
and isinstance(other_obj, float)
and isinstance(foo, str)
or (isinstance(bar, float) or isinstance(bar, str))
and (isinstance(baz, float) or isinstance(baz, int))
):
pass


def check(x):
if x == 1 or x == 2 or x == 3:
print("Yes")
elif x != 2 or x != 3:
print("also true")

elif x in (2, 3) or x in (5, 4):
print("Here")

elif x == 10 or x == 20 or x == 30 and x == 40:
print("Sweet!")

elif x == 10 or x == 20 or x == 30:
print("Why even?")

def chained_comparison():
a = 1
b = 2
c = 3
return a < b and b < c

if __name__ == "__main__":
args = ["--disable", "all"]
f = open("/tmp/.deepsource.toml", "r")
f.write("config file.")
Comment on lines +121 to +122

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`open(..., "r")` then `write()` crashes module entry path


Top-level script code opens /tmp/.deepsource.toml in read mode and writes to it. Running the file directly will raise an exception immediately.

Use with open(path, "w") as f: so startup logic proceeds predictably.

f.close()
assert args is not None
for i in range(len(args)):
has_truthy = True if args[i] else False
assert has_truthy is not None
if has_truthy:
break
Loading