From c901ffe4dfdb36b987f12a878f9653353880619f Mon Sep 17 00:00:00 2001 From: Jai Date: Thu, 2 Jan 2020 14:17:56 -0800 Subject: [PATCH 01/31] Add results URL in README Signed-off-by: Jai --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f04e783a0..b2c5ddeb6 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# Demo repository +# Demo repository - Python + +This repository demonstrates sample issues in Python code raised by DeepSource. + +Results: https://deepsource.io/gh/deepsourcelabs/demo-python/issues/ From 50a412b279a12b1b06d3bc2a9887cc0e680001da Mon Sep 17 00:00:00 2001 From: Rahul Jha Date: Tue, 11 Feb 2020 17:19:58 +0530 Subject: [PATCH 02/31] Add DeepSource Badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b2c5ddeb6..af1613e43 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Demo repository - Python +[![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) + This repository demonstrates sample issues in Python code raised by DeepSource. Results: https://deepsource.io/gh/deepsourcelabs/demo-python/issues/ From cae4bddbc1bfefb3074e00fd8d96076b76fbbd16 Mon Sep 17 00:00:00 2001 From: Sanket Saurav Date: Sat, 14 Mar 2020 17:21:33 -0700 Subject: [PATCH 03/31] Update code.py --- code.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code.py b/code.py index cfbc27724..8e01600a9 100644 --- a/code.py +++ b/code.py @@ -39,6 +39,10 @@ def main(options: dict = {}) -> str: f.write("config file.") f.close() + +def moon_chooser(moons=['europa', 'callisto', 'phobos']): + return random.choice(moons) + if __name__ == '__main__': args = ['--disable', 'all'] From 19e2be4e0d85ee187a200f51b10653c25fffeb59 Mon Sep 17 00:00:00 2001 From: Jai Pradeesh Date: Fri, 24 Apr 2020 07:54:26 +0530 Subject: [PATCH 04/31] Update README.md --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index af1613e43..99b19b1a6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,31 @@ -# Demo repository - Python +

+ +

+ +

+ Documentation | + Get Started | + Discuss +

+ +

+ DeepSource helps you ship good quality code. +

+ +

+ +--- -[![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) +# Demo repository - Python This repository demonstrates sample issues in Python code raised by DeepSource. -Results: https://deepsource.io/gh/deepsourcelabs/demo-python/issues/ +[![DeepSource](https://static.deepsource.io/deepsource-badge-light.svg)](https://deepsource.io/gh/deepsourcelabs/cli/?ref=repository-badge) + +### Report + +[https://deepsource.io/gh/deepsourcelabs/demo-python/issues/](https://deepsource.io/gh/deepsourcelabs/demo-python/issues/) + +### Documentation + +[https://deepsource.io/docs/analyzer/python.html](https://deepsource.io/docs/analyzer/python.html) From 127cc727a2b33770b5095c7df6a52641c459fd3d Mon Sep 17 00:00:00 2001 From: Jai Pradeesh Date: Fri, 24 Apr 2020 07:59:29 +0530 Subject: [PATCH 05/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99b19b1a6..c210321a4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This repository demonstrates sample issues in Python code raised by DeepSource. -[![DeepSource](https://static.deepsource.io/deepsource-badge-light.svg)](https://deepsource.io/gh/deepsourcelabs/cli/?ref=repository-badge) +[![DeepSource](https://static.deepsource.io/deepsource-badge-light.svg)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) ### Report From 4aa06c5196e2cb7e64ecc1f2b0127fbdb1cb19f1 Mon Sep 17 00:00:00 2001 From: Jai Pradeesh Date: Fri, 24 Apr 2020 08:00:17 +0530 Subject: [PATCH 06/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c210321a4..916c8aecf 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This repository demonstrates sample issues in Python code raised by DeepSource. -[![DeepSource](https://static.deepsource.io/deepsource-badge-light.svg)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) +[![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) ### Report From 92ea1e6d938e2e3db83cf067f2b4ba0c85857366 Mon Sep 17 00:00:00 2001 From: Sanket Saurav Date: Mon, 11 May 2020 21:09:45 +0530 Subject: [PATCH 07/31] Add some security issues (fix #34) --- code.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/code.py b/code.py index 8e01600a9..3de862283 100644 --- a/code.py +++ b/code.py @@ -1,7 +1,12 @@ import random import pdb import sys +import os +import subprocess +from django.db.models.expressions import RawSQL + +AWS_SECRET_KEY = 'd6s$f9g!j8mg7hw?n&2' class BaseNumberGenerator: def __init__(self): @@ -39,11 +44,20 @@ def main(options: dict = {}) -> str: f.write("config file.") f.close() - + def moon_chooser(moons=['europa', 'callisto', 'phobos']): 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') + subprocess.Popen('/bin/chown *', shell=True) + o.system("/bin/tar xvzf *") + if __name__ == '__main__': args = ['--disable', 'all'] for i in range(len(args)): From 2316e689facc8b4ea67258230b5cbce5c7d6c8d4 Mon Sep 17 00:00:00 2001 From: DeepSource Bot Date: Mon, 6 Jul 2020 10:13:22 +0000 Subject: [PATCH 08/31] Update .deepsource.toml --- .deepsource.toml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.deepsource.toml b/.deepsource.toml index d16516ad0..c0f48c7d2 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -1,15 +1,12 @@ version = 1 -test_patterns = [ - "test_*.py" -] - [[analyzers]] name = "python" enabled = true -runtime_version = "3.x.x" [analyzers.meta] - max_line_length = 88 - skip_doc_coverage = ["module", "magic", "init"] - type_checker = 'mypy' + runtime_version = "3.x.x" + +[[transformers]] +name = "black" +enabled = true \ No newline at end of file From b3907ba96caa65668f3f8b96663f6629f607e860 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2020 10:13:54 +0000 Subject: [PATCH 09/31] Format code with Black --- code.py | 25 ++++++++++++++----------- test_code.py | 1 + 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/code.py b/code.py index 3de862283..fc0a9042b 100644 --- a/code.py +++ b/code.py @@ -6,11 +6,12 @@ from django.db.models.expressions import RawSQL -AWS_SECRET_KEY = 'd6s$f9g!j8mg7hw?n&2' +AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" + class BaseNumberGenerator: def __init__(self): - self.limits = (1,10) + self.limits = (1, 10) def get_number(self, min_max): raise NotImplemented @@ -28,10 +29,10 @@ def get_number(self, min_max=[1, 10]): def main(options: dict = {}) -> str: pdb.set_trace() - if 'run' in options: - value = options['run'] + if "run" in options: + value = options["run"] else: - value = 'default_value' + value = "default_value" if type(value) != str: raise Exception() @@ -40,12 +41,12 @@ def main(options: dict = {}) -> str: sorted(value, key=lambda k: len(k)) - f = open('/tmp/.deepsource.toml', 'r') + f = open("/tmp/.deepsource.toml", "r") f.write("config file.") f.close() -def moon_chooser(moons=['europa', 'callisto', 'phobos']): +def moon_chooser(moons=["europa", "callisto", "phobos"]): return random.choice(moons) @@ -53,13 +54,15 @@ 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') - subprocess.Popen('/bin/chown *', shell=True) + os.tempnam("dir1") + subprocess.Popen("/bin/chown *", shell=True) o.system("/bin/tar xvzf *") -if __name__ == '__main__': - args = ['--disable', 'all'] + +if __name__ == "__main__": + args = ["--disable", "all"] for i in range(len(args)): has_truthy = True if args[i] else False if has_truthy: diff --git a/test_code.py b/test_code.py index a180a32d5..864963a4e 100644 --- a/test_code.py +++ b/test_code.py @@ -1,5 +1,6 @@ from code import RandomNumberGenerator + def test_random_number_generator(): """Test random number generator.""" assert RandomNumberGenerator().get_number() != RandomNumberGenerator().get_number() From bdf3d997d8339afe3e5ef423b06a043ba11b0159 Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Thu, 24 Sep 2020 15:48:21 +0530 Subject: [PATCH 10/31] Update code.py --- code.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code.py b/code.py index fc0a9042b..1f1d8bf2b 100644 --- a/code.py +++ b/code.py @@ -61,6 +61,25 @@ def tar_something(): o.system("/bin/tar xvzf *") +def bad_isinstance(object, other_obj, foo, bar, baz): + if ( + 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 + + if __name__ == "__main__": args = ["--disable", "all"] for i in range(len(args)): From 4886e9e835e895d1750c868cb8dfb57febb1aa41 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 24 Sep 2020 10:18:40 +0000 Subject: [PATCH 11/31] Format code with black This commit fixes the style issues introduced in bdf3d99 according to the output from black. Details: https://deepsource.io/gh/deepsourcelabs/demo-python/transform/4fe8eaac-b5d6-496d-a64f-97317a76cc3f/ --- code.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/code.py b/code.py index 1f1d8bf2b..78771b940 100644 --- a/code.py +++ b/code.py @@ -68,17 +68,11 @@ def bad_isinstance(object, other_obj, foo, bar, baz): 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) - ) + or (isinstance(bar, float) or isinstance(bar, str)) + and (isinstance(baz, float) or isinstance(baz, int)) ): pass - + if __name__ == "__main__": args = ["--disable", "all"] From 71e57b0b0d63890161776f68a354eccb516ac1b4 Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Thu, 24 Sep 2020 16:53:36 +0530 Subject: [PATCH 12/31] Update code.py --- code.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code.py b/code.py index 78771b940..c0daa6e82 100644 --- a/code.py +++ b/code.py @@ -61,11 +61,14 @@ def tar_something(): o.system("/bin/tar xvzf *") -def bad_isinstance(object, other_obj, foo, bar, baz): +def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz): if ( - isinstance(object, int) - or isinstance(object, float) - or isinstance(object, str) + 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)) From c958376110fb3bce9449ca33c4d4a31aeb631a2f Mon Sep 17 00:00:00 2001 From: Sourya Vatsyayan Date: Fri, 2 Oct 2020 13:35:12 +0530 Subject: [PATCH 13/31] Add new badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 916c8aecf..7394cd26b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This repository demonstrates sample issues in Python code raised by DeepSource. -[![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) +[![DeepSource](https://deepsource.io/gh/deepsourcelabs/demo-python.svg/?label=active+issues&show_trend=true)](https://deepsource.io/gh/deepsourcelabs/demo-python/?ref=repository-badge) ### Report From cd78a76328fd8bf6db1dcacd40710bf664ea8558 Mon Sep 17 00:00:00 2001 From: Srijan Saurav Date: Fri, 6 Nov 2020 11:44:45 +0530 Subject: [PATCH 14/31] Update examples --- .deepsource.toml | 3 ++- .github/workflows/CI.yml | 38 ++++++++++++++++++++++++++++ code.py | 54 ++++++++++++++++++++++++++++++++++++++-- duplicate_bases_class.py | 25 +++++++++++++++++++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/CI.yml create mode 100644 duplicate_bases_class.py diff --git a/.deepsource.toml b/.deepsource.toml index c0f48c7d2..c06ccf5b9 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -6,7 +6,8 @@ enabled = true [analyzers.meta] runtime_version = "3.x.x" + type_checker = "mypy" [[transformers]] name = "black" -enabled = true \ No newline at end of file +enabled = true diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 000000000..27d438c22 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,38 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + +jobs: + run-tests: + runs-on: [ubuntu-latest] + + env: + DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up python3.9 + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Run tests + run: | + pip install pytest-cov + pytest --cov=./ --cov-report=xml + + - name: Report test coverage to DeepSource + uses: deepsourcelabs/test-coverage-action@master + with: + key: python + coverage-file: coverage.xml + dsn: ${{ secrets.DEEPSOURCE_DSN }} diff --git a/code.py b/code.py index c0daa6e82..b0b54f308 100644 --- a/code.py +++ b/code.py @@ -1,23 +1,38 @@ import random import pdb -import sys +import sys as sys import os import subprocess from django.db.models.expressions import RawSQL AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" +*FIRST = [1, 2, 3] +(*FIRST, ) = [1, 2, 3] +*FIRST, a, b = [1, 2, 3] class BaseNumberGenerator: + """Declare a method -- `get_number`.""" + def __init__(self): self.limits = (1, 10) def get_number(self, min_max): raise NotImplemented + 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 @@ -46,7 +61,10 @@ def main(options: dict = {}) -> str: f.close() -def moon_chooser(moons=["europa", "callisto", "phobos"]): +def moon_chooser(moon, moons=["europa", "callisto", "phobos"]): + if moon is not None: + moons.append(moon) + return random.choice(moons) @@ -77,6 +95,38 @@ def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz): 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"] for i in range(len(args)): diff --git a/duplicate_bases_class.py b/duplicate_bases_class.py new file mode 100644 index 000000000..78a24a418 --- /dev/null +++ b/duplicate_bases_class.py @@ -0,0 +1,25 @@ +import abc +class Base: + def __init__(self): + self.base = 1 + + +class BaseOne: + def __init__(self): + self.base_one = 2 + + +class Child(Base, BaseOne, Base, BaseOne): + """Some Child class""" + + +class ChildOne( + Base, + BaseOne, + Base, + BaseOne, + abc.ABC, + abc.ABCMeta, + abc.ABCMeta +): + """Class with duplicate bases""" From 44551c87296462fced90ffeb8a712e5fd9c71a46 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix-local[bot]" <61578317+deepsource-autofix-local[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2020 06:33:19 +0000 Subject: [PATCH 15/31] Format code with black This commit fixes the style issues introduced in cd78a76 according to the output from black. Details: https://deepsource.icu/gh/deepsourcelabs/demo-python/transform/d64bceeb-0344-4a57-86fd-cc358cb916fc/ --- code.py | 21 +++++++-------------- duplicate_bases_class.py | 12 +++--------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/code.py b/code.py index b0b54f308..0c339a94a 100644 --- a/code.py +++ b/code.py @@ -8,7 +8,7 @@ AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" *FIRST = [1, 2, 3] -(*FIRST, ) = [1, 2, 3] +(*FIRST,) = [1, 2, 3] *FIRST, a, b = [1, 2, 3] @@ -23,10 +23,12 @@ def get_number(self, min_max): def smethod(): """static method-to-be""" + smethod = staticmethod(smethod) def cmethod(cls, something): """class method-to-be""" + cmethod = classmethod(cmethod) @@ -96,27 +98,18 @@ def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz): def check(x): - if x == 1 or x ==2 or x ==3: - print('Yes') + 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 - ): + elif x == 10 or x == 20 or x == 30 and x == 40: print("Sweet!") - elif ( - x == 10 - or x == 20 - or x == 30 - ): + elif x == 10 or x == 20 or x == 30: print("Why even?") diff --git a/duplicate_bases_class.py b/duplicate_bases_class.py index 78a24a418..ad1dfe8bc 100644 --- a/duplicate_bases_class.py +++ b/duplicate_bases_class.py @@ -1,4 +1,6 @@ import abc + + class Base: def __init__(self): self.base = 1 @@ -13,13 +15,5 @@ class Child(Base, BaseOne, Base, BaseOne): """Some Child class""" -class ChildOne( - Base, - BaseOne, - Base, - BaseOne, - abc.ABC, - abc.ABCMeta, - abc.ABCMeta -): +class ChildOne(Base, BaseOne, Base, BaseOne, abc.ABC, abc.ABCMeta, abc.ABCMeta): """Class with duplicate bases""" From ebe6f55a1c4a06d7fac7fda0d0ec7caa11e38ca0 Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Fri, 6 Nov 2020 12:10:01 +0530 Subject: [PATCH 16/31] Update CI.yml --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 27d438c22..629259d9c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -27,8 +27,8 @@ jobs: - name: Run tests run: | - pip install pytest-cov - pytest --cov=./ --cov-report=xml + pip install pytest-cov + pytest --cov=./ --cov-report=xml - name: Report test coverage to DeepSource uses: deepsourcelabs/test-coverage-action@master From 65c20efbeb2987ea827de8c590a2b91c767463a3 Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Fri, 6 Nov 2020 12:47:05 +0530 Subject: [PATCH 17/31] Fix tests (#121) --- .github/workflows/CI.yml | 2 +- Pipfile | 11 +++++++++++ assignment.py | 3 +++ code.py => demo_code.py | 5 +---- test_code.py | 6 ------ tests/__init__.py | 0 tests/test_code.py | 6 ++++++ 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 Pipfile create mode 100644 assignment.py rename code.py => demo_code.py (95%) delete mode 100644 test_code.py create mode 100644 tests/__init__.py create mode 100644 tests/test_code.py diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 629259d9c..8acfabfc4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -27,7 +27,7 @@ jobs: - name: Run tests run: | - pip install pytest-cov + pip install pytest-cov django pytest --cov=./ --cov-report=xml - name: Report test coverage to DeepSource diff --git a/Pipfile b/Pipfile new file mode 100644 index 000000000..b5846df18 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] + +[requires] +python_version = "3.8" diff --git a/assignment.py b/assignment.py new file mode 100644 index 000000000..f401a7daf --- /dev/null +++ b/assignment.py @@ -0,0 +1,3 @@ +*FIRST = [1, 2, 3] +(*FIRST,) = [1, 2, 3] +*FIRST, a, b = [1, 2, 3] diff --git a/code.py b/demo_code.py similarity index 95% rename from code.py rename to demo_code.py index 0c339a94a..f0d28f25f 100644 --- a/code.py +++ b/demo_code.py @@ -4,12 +4,9 @@ import os import subprocess -from django.db.models.expressions import RawSQL +# from django.db.models.expressions import RawSQL AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" -*FIRST = [1, 2, 3] -(*FIRST,) = [1, 2, 3] -*FIRST, a, b = [1, 2, 3] class BaseNumberGenerator: diff --git a/test_code.py b/test_code.py deleted file mode 100644 index 864963a4e..000000000 --- a/test_code.py +++ /dev/null @@ -1,6 +0,0 @@ -from code import RandomNumberGenerator - - -def test_random_number_generator(): - """Test random number generator.""" - assert RandomNumberGenerator().get_number() != RandomNumberGenerator().get_number() diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_code.py b/tests/test_code.py new file mode 100644 index 000000000..e444f72e1 --- /dev/null +++ b/tests/test_code.py @@ -0,0 +1,6 @@ +from demo_code import RandomNumberGenerator + + +def test_random_number_generator(): + """Test random number generator.""" + assert RandomNumberGenerator().get_number() From a0e7b0958219d18353ece121a18fe419a5d1653a Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Mon, 9 Nov 2020 13:58:44 +0530 Subject: [PATCH 18/31] Enable test-coverage analyzer --- .deepsource.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.deepsource.toml b/.deepsource.toml index c06ccf5b9..4ff1651b0 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -11,3 +11,7 @@ enabled = true [[transformers]] name = "black" enabled = true + +[[analyzers]] +name = "test-coverage" +enabled = true From c8c313be065c9b5e20949f3f03151e40c075a62d Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Mon, 9 Nov 2020 13:58:57 +0530 Subject: [PATCH 19/31] Update CI.yml (#125) --- .github/workflows/CI.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8acfabfc4..f6151ad26 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -31,8 +31,6 @@ jobs: pytest --cov=./ --cov-report=xml - name: Report test coverage to DeepSource - uses: deepsourcelabs/test-coverage-action@master - with: - key: python - coverage-file: coverage.xml - dsn: ${{ secrets.DEEPSOURCE_DSN }} + run: | + curl https://deepsource.io/cli | sh + ./bin/deepsource report --analyzer test-coverage --key python --value-file ./coverage.xml From d88364925bb8c8bcf6d8d73dcfcd93ea8bd246e1 Mon Sep 17 00:00:00 2001 From: Shruddha Bhat <77613385+shruddha-deepsource@users.noreply.github.com> Date: Tue, 9 Feb 2021 20:56:06 +0530 Subject: [PATCH 20/31] Add CODEOWNERS --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..e4c80d3a7 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* srijan@deepsource.io \ No newline at end of file From a58f9a96d55c0e224f8f6e58c4713748f589922a Mon Sep 17 00:00:00 2001 From: Shruddha Bhat <77613385+shruddha-deepsource@users.noreply.github.com> Date: Tue, 2 Mar 2021 00:37:20 +0530 Subject: [PATCH 21/31] Stale Bot config --- .github/stale.yml | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/stale.yml diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 000000000..4a66712b5 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,56 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +# Number of days of inactivity before an Issue or Pull Request becomes stale +daysUntilStale: 90 + +# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. +# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. +daysUntilClose: 7 + +# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) +onlyLabels: [] + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable +exemptLabels: + - pinned + - security + - Status:WIP + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false + +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false + +# Set to true to ignore issues with an assignee (defaults to false) +exemptAssignees: false + +# Label to use when marking as stale +staleLabel: stale + +# Comment to post when marking as stale. Set to `false` to disable +markComment: > + Is this issue still relevant? + There has been no recent activity found and is considered stale. + If relevant please comment or update to unstale. + +# Comment to post when closing a stale Issue or Pull Request. +closeComment: > + This issue has been automatically closed because of inactivity. + You can re-open if needed. + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 5 + +# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls': +pulls: + daysUntilStale: 90 + + markComment: > + Is this pull request still relevant? + There has been no recent activity found and is considered stale. + If relevant please comment or update to unstale. + + closeComment: > + This pull request has been automatically closed because of inactivity. + You can re-open it if needed. From c2a154d01b8ff4f543a996509500b607782b2a9e Mon Sep 17 00:00:00 2001 From: Faisal Riyaz <76944076+faisal-deepsource@users.noreply.github.com> Date: Mon, 7 Jun 2021 11:16:07 +0530 Subject: [PATCH 22/31] Add more snippets (#211) --- demo_code.py | 14 ++++++++++++++ return_not_implemented.py | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 return_not_implemented.py diff --git a/demo_code.py b/demo_code.py index f0d28f25f..89dab5f94 100644 --- a/demo_code.py +++ b/demo_code.py @@ -41,6 +41,16 @@ def get_number(self, min_max=[1, 10]): return random.randint(*min_max) +class ImaginaryNumber: + """Class to represent an imaginary number.""" + def __init__(self): + self.real = 0 + self.imaginary = 1 + + def __getattr__(self, key): + return key + + def main(options: dict = {}) -> str: pdb.set_trace() if "run" in options: @@ -116,6 +126,10 @@ def chained_comparison(): c = 3 return a < b and b < c +def wrong_callable(): + number = ImaginaryNumber() + if hasattr(number, '__call__'): + return number() if __name__ == "__main__": args = ["--disable", "all"] diff --git a/return_not_implemented.py b/return_not_implemented.py new file mode 100644 index 000000000..c9d7e580b --- /dev/null +++ b/return_not_implemented.py @@ -0,0 +1,25 @@ +class RealNumber: + """Represents a real number.""" + def __init__(self, val): + self.val = val + + def __add__(self, other): + raise NotImplementedError + +class ComplexNumber: + """Represents an imaginary number.""" + def __init__(self, x, y): + self.x = x + self.y = y + + def __add__(self, other): + return self.val + other.val + + def __radd__(self, other): + res = (self.x + other.val, self.y) + return res + +if __name__ == "__main__": + complex_num = ComplexNumber(2, 5) + real_num = RealNumber(32) + return real_num + complex_num From 0ba82b35cc915a2630b2826f90903d66638a602b Mon Sep 17 00:00:00 2001 From: Faisal Riyaz <76944076+faisal-deepsource@users.noreply.github.com> Date: Tue, 8 Jun 2021 21:29:07 +0530 Subject: [PATCH 23/31] Add new issue (#214) * Add typecheck issue * Add BAN-B608, BAN-B501 * Add PY-S6007 * Add PTC-W0052, PTC-W0046, PTC-W6002 * Add W0050, W0052, W0055 --- demo_code.py | 4 +++- django_issues.py | 10 ++++++++++ miscellaneous.py | 23 +++++++++++++++++++++++ security.py | 32 ++++++++++++++++++++++++++++++++ tests/test_code.py | 5 +++++ type_checks.py | 7 +++++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 django_issues.py create mode 100644 miscellaneous.py create mode 100644 security.py create mode 100644 type_checks.py diff --git a/demo_code.py b/demo_code.py index 89dab5f94..68313e68b 100644 --- a/demo_code.py +++ b/demo_code.py @@ -3,12 +3,13 @@ import sys as sys import os import subprocess +import ssl + # from django.db.models.expressions import RawSQL AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" - class BaseNumberGenerator: """Declare a method -- `get_number`.""" @@ -83,6 +84,7 @@ def get_users(): def tar_something(): + context = ssl._create_stdlib_context() os.tempnam("dir1") subprocess.Popen("/bin/chown *", shell=True) o.system("/bin/tar xvzf *") diff --git a/django_issues.py b/django_issues.py new file mode 100644 index 000000000..a0d19177b --- /dev/null +++ b/django_issues.py @@ -0,0 +1,10 @@ +import datetime + +from django.http import HttpResponse +from django.views.decorators.http import require_http_methods + +@require_http_methods(["GET", "POST"]) # Sensitive +def current_datetime(request): + now = datetime.datetime.now() + html = "It is %s." % now + return HttpResponse(html) diff --git a/miscellaneous.py b/miscellaneous.py new file mode 100644 index 000000000..a3b4fa7e6 --- /dev/null +++ b/miscellaneous.py @@ -0,0 +1,23 @@ +from utils import get_next, render_to_frontend, render_bg + +class Orange: + """Represents the fruit orange.""" + orange = "#FFA500" + + # Other class implementations + + def get_orange(self): + return self.orange + +def render(): + fruit = Orange() + render_to_frontend(fruit.orange) # Rendering a color, but one can get confused with the fruit + render_bg(fruit.get_orange) + +def play_with_magic_numbers(): + magic_numbers = {0, 1, 1, 2, 3, 5} + + for elem in magic_numbers: + magic_numbers.add(get_next(elem)) + return magic_numbers + diff --git a/security.py b/security.py new file mode 100644 index 000000000..1916df298 --- /dev/null +++ b/security.py @@ -0,0 +1,32 @@ +import sqlite3 +import requests + +class ResidentsDb: + def __init__(self, table_name, mapping_function, duration): + """Set location on disk data cache will reside. + Also sets the table name and refresh duration + """ + self.table_name = table_name + self.mapping_function = mapping_function + self.disk_location = DISK_LOCATION_DEFAULT + self.duration = duration + self.conn = None + self.cursor = None + + def open(self): + """ Opens connection to sqlite database.""" + self.conn = sqlite3.connect(self.dbname) + self.cursor = self.conn.cursor() + + def get_id_from_name(self, name): + """Get id of resident from name.""" + data = self.cursor.execute("SELECT id FROM userdata WHERE Name ={};".format(name)) + self.conn.commit() + return data + +def fetch_version(request): + """Fetch verison of bgmi.""" + version = requests.get( + "https://pypi.python.org/pypi/bgmi/json", verify=False + ).json()["info"]["version"] + return version diff --git a/tests/test_code.py b/tests/test_code.py index e444f72e1..159c78dfb 100644 --- a/tests/test_code.py +++ b/tests/test_code.py @@ -1,6 +1,11 @@ +import unittest from demo_code import RandomNumberGenerator def test_random_number_generator(): """Test random number generator.""" assert RandomNumberGenerator().get_number() + +class Tests(unittest.TestCase): + def my_test(self, arg1, arg2): + self.assertEquals(arg1, arg2) diff --git a/type_checks.py b/type_checks.py new file mode 100644 index 000000000..811da988f --- /dev/null +++ b/type_checks.py @@ -0,0 +1,7 @@ +def greet_all(names: list[str]) -> None: + for name in names: + print('Hello ' + name) + +if __name__ == "__main__": + heights = [5.5, 6, 5.9] + greet_all(heights) From cf5403a9b99384c7e6df02abd935cbda1d979523 Mon Sep 17 00:00:00 2001 From: Shruddha Bhat <77613385+shruddha-deepsource@users.noreply.github.com> Date: Fri, 2 Jul 2021 14:46:54 +0530 Subject: [PATCH 24/31] Enable Deepsource Secrets Analyzer --- .deepsource.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.deepsource.toml b/.deepsource.toml index 4ff1651b0..a0c44f91e 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -15,3 +15,7 @@ enabled = true [[analyzers]] name = "test-coverage" enabled = true + +[[analyzers]] +name = "secrets" +enabled = true From d334944c355c00ad69ae72183af1706dbbd02495 Mon Sep 17 00:00:00 2001 From: Shruddha Bhat <77613385+shruddha-deepsource@users.noreply.github.com> Date: Mon, 8 Nov 2021 13:26:42 +0530 Subject: [PATCH 25/31] Disable Stale Bot --- .github/stale.yml | 56 ----------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 .github/stale.yml diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 4a66712b5..000000000 --- a/.github/stale.yml +++ /dev/null @@ -1,56 +0,0 @@ -# Configuration for probot-stale - https://github.com/probot/stale - -# Number of days of inactivity before an Issue or Pull Request becomes stale -daysUntilStale: 90 - -# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. -# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. -daysUntilClose: 7 - -# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) -onlyLabels: [] - -# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable -exemptLabels: - - pinned - - security - - Status:WIP - -# Set to true to ignore issues in a project (defaults to false) -exemptProjects: false - -# Set to true to ignore issues in a milestone (defaults to false) -exemptMilestones: false - -# Set to true to ignore issues with an assignee (defaults to false) -exemptAssignees: false - -# Label to use when marking as stale -staleLabel: stale - -# Comment to post when marking as stale. Set to `false` to disable -markComment: > - Is this issue still relevant? - There has been no recent activity found and is considered stale. - If relevant please comment or update to unstale. - -# Comment to post when closing a stale Issue or Pull Request. -closeComment: > - This issue has been automatically closed because of inactivity. - You can re-open if needed. - -# Limit the number of actions per hour, from 1-30. Default is 30 -limitPerRun: 5 - -# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls': -pulls: - daysUntilStale: 90 - - markComment: > - Is this pull request still relevant? - There has been no recent activity found and is considered stale. - If relevant please comment or update to unstale. - - closeComment: > - This pull request has been automatically closed because of inactivity. - You can re-open it if needed. From 2e8e65774e668b9d47411168fdd7e4e1d9a65473 Mon Sep 17 00:00:00 2001 From: Siddhant N Trivedi <68370997+siddhant-deepsource@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:43:38 +0530 Subject: [PATCH 26/31] fix: change logo URL (#244) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7394cd26b..51bf367cc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- +

From a3dcdc09dbce3930b5004ddce79fd2fa69376ef1 Mon Sep 17 00:00:00 2001 From: deepak-deepsource <104898724+deepak-deepsource@users.noreply.github.com> Date: Thu, 12 May 2022 17:27:50 +0530 Subject: [PATCH 27/31] Create startswith_endswith.py --- startswith_endswith.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 startswith_endswith.py diff --git a/startswith_endswith.py b/startswith_endswith.py new file mode 100644 index 000000000..5f91fba5d --- /dev/null +++ b/startswith_endswith.py @@ -0,0 +1,7 @@ +s = 'asdas' + +if s.startswith('a') or s.startswith('b'): + pass + +if s.endswith('x') or s.endswith('y'): + pass From d7265a695a145a0d86a611ac56ee2a45c0d4fe66 Mon Sep 17 00:00:00 2001 From: DeepSource Bot Date: Thu, 12 May 2022 12:02:44 +0000 Subject: [PATCH 28/31] Update .deepsource.toml --- .deepsource.toml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.deepsource.toml b/.deepsource.toml index a0c44f91e..aebeb0fcf 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -5,17 +5,4 @@ name = "python" enabled = true [analyzers.meta] - runtime_version = "3.x.x" - type_checker = "mypy" - -[[transformers]] -name = "black" -enabled = true - -[[analyzers]] -name = "test-coverage" -enabled = true - -[[analyzers]] -name = "secrets" -enabled = true + runtime_version = "3.x.x" \ No newline at end of file From 7be3d423ccae86b70790e64b1b1b592d5fe8128b Mon Sep 17 00:00:00 2001 From: DeepSource Bot Date: Fri, 27 May 2022 10:46:59 +0000 Subject: [PATCH 29/31] Update .deepsource.toml From c0db7467f47df5ef5b495bfbc18f9b8601341ac8 Mon Sep 17 00:00:00 2001 From: DeepSource Bot Date: Mon, 17 Oct 2022 06:36:24 +0000 Subject: [PATCH 30/31] Update .deepsource.toml From e4eac8f4911fa8403638a57b8012b291caca6edf Mon Sep 17 00:00:00 2001 From: DeepSource Bot Date: Wed, 16 Nov 2022 06:49:29 +0000 Subject: [PATCH 31/31] Update .deepsource.toml --- .deepsource.toml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.deepsource.toml b/.deepsource.toml index aebeb0fcf..2f78360fb 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -1,8 +1,5 @@ version = 1 [[analyzers]] -name = "python" -enabled = true - - [analyzers.meta] - runtime_version = "3.x.x" \ No newline at end of file +name = "cxx" +enabled = true \ No newline at end of file