-
Notifications
You must be signed in to change notification settings - Fork 6
Add RandomNumberGenerator and utility functions #32
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented import The import statement |
||
|
|
||
| AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded A hardcoded secret There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded secret A secret key is hardcoded in the source file. This is a significant security risk, as it exposes sensitive credentials to anyone with access to the codebase. Secrets should be managed through a secure vault or environment variables, not stored in code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded sensitive credential A hardcoded AWS secret key is present in the codebase. This is a significant security risk, as it exposes sensitive credentials to anyone with access to the source code. Secrets should be managed through a secure vault or environment variables, not stored in code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded The |
||
|
|
||
|
|
||
| class BaseNumberGenerator: | ||
| """Declare a method -- `get_number`.""" | ||
|
|
||
| def __init__(self): | ||
| self.limits = (1, 10) | ||
|
|
||
| def get_number(self, min_max): | ||
| raise NotImplemented | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The code raises There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable The variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function The function |
||
|
|
||
| def smethod(): | ||
| """static method-to-be""" | ||
|
|
||
| smethod = staticmethod(smethod) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method The method |
||
|
|
||
| def cmethod(cls, something): | ||
| """class method-to-be""" | ||
|
|
||
| cmethod = classmethod(cmethod) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function The function
Comment on lines
+22
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outdated syntax is used to define static and class methods The functions
Comment on lines
+22
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static and class methods are defined in an outdated way The |
||
|
|
||
|
|
||
| class RandomNumberGenerator: | ||
| """Generate random numbers.""" | ||
|
|
||
| def limits(self): | ||
| return self.limits | ||
|
|
||
| def get_number(self, min_max=[1, 10]): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable list The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable default argument The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method The method |
||
| """Get a random number between min and max.""" | ||
| assert all([isinstance(i, int) for i in min_max]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert statement The |
||
| return random.randint(*min_max) | ||
|
|
||
|
|
||
| def main(options: dict = {}) -> str: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable dictionary The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A mutable dictionary is used as a default function argument The default argument for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable default argument The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function The default argument |
||
| pdb.set_trace() | ||
|
Comment on lines
+2
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debugger The code imports the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debugger The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debugger breakpoint A debugger breakpoint There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A The code contains a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of
|
||
| 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)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result of the The result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of The result of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result of the The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lambda expression The |
||
|
|
||
| f = open("/tmp/.deepsource.toml", "r") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File created at a predictable path in a public directory A file is created at a predictable path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Local variable The local variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File is opened with A file is opened but not closed using a |
||
| f.write("config file.") | ||
|
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attempting to write to a file opened in read-only mode The file
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File is opened in read-only mode but is then written to The file is opened in read mode ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attempting to write to a file opened in read-only mode The file is opened in read mode (
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attempting to write to a file opened in read-only mode The file at |
||
| f.close() | ||
|
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File is not opened using a The file is opened using |
||
|
|
||
|
|
||
| def moon_chooser(moon, moons=["europa", "callisto", "phobos"]): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable list is used as a default argument for The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A mutable list is used as a default function argument The default argument for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable default argument The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function The default argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable default
|
||
| 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, [])) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of The code uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of The function
Comment on lines
+72
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of The code uses |
||
|
|
||
|
|
||
| def tar_something(): | ||
| os.tempnam("dir1") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Insecure function The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deprecated function The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Insecure and deprecated function The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of insecure and deprecated function The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of
|
||
| subprocess.Popen("/bin/chown *", shell=True) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The command There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of The |
||
| o.system("/bin/tar xvzf *") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The code calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable The code attempts to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The code uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of The |
||
|
|
||
|
|
||
| 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)) | ||
| ): | ||
|
Comment on lines
+83
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple The |
||
| pass | ||
|
|
||
|
|
||
| def check(x): | ||
| if x == 1 or x == 2 or x == 3: | ||
| print("Yes") | ||
| elif x != 2 or x != 3: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition The condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition The condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition The condition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition The condition |
||
| 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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Condition mixes The condition mixes |
||
| print("Sweet!") | ||
|
|
||
| elif x == 10 or x == 20 or x == 30: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable The variable |
||
| print("Why even?") | ||
|
|
||
| def chained_comparison(): | ||
| a = 1 | ||
| b = 2 | ||
| c = 3 | ||
| return a < b and b < c | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparison The expression There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A chained comparison is written in a verbose way The chained comparison There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expression The boolean operation |
||
|
|
||
| if __name__ == "__main__": | ||
| args = ["--disable", "all"] | ||
| f = open("/tmp/.deepsource.toml", "r") | ||
| f.write("config file.") | ||
|
Comment on lines
+121
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attempting to write to a file opened in read-only mode The file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File object The file
Comment on lines
+60
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attempting to write to a file opened in read mode The code attempts to write to a file that was opened in read-only mode ( |
||
| f.close() | ||
| assert args is not None | ||
| for i in range(len(args)): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looping over The code iterates using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unpythonic loop using The loop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unpythonic loop A C-style There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Range(len(args)) iteration used instead of The code uses |
||
| has_truthy = True if args[i] else False | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verbose boolean conversion The expression There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable The variable |
||
| assert has_truthy is not None | ||
| if has_truthy: | ||
| break | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module
pdbimported at line 2 risks debug statements in productionThe module
pdbis imported on line 2 for debugging purposes but left in the checked-in code. This increases the risk of unintentional debugger activation in production, which can halt execution and expose internals. Remove thepdbimport and all related debug calls before deployment.