diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..95ca975 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..e955772 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '27 12 * * 4' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/01-encapsulation-1.py b/01-encapsulation/01-encapsulation-1.py similarity index 96% rename from 01-encapsulation-1.py rename to 01-encapsulation/01-encapsulation-1.py index 7954dac..93562da 100644 --- a/01-encapsulation-1.py +++ b/01-encapsulation/01-encapsulation-1.py @@ -12,14 +12,14 @@ class MyClass(object): - def set_val(self, val): self.value = val def get_val(self): - print(self.value) + # print(self.value) return self.value + a = MyClass() b = MyClass() @@ -38,4 +38,4 @@ def get_val(self): # a) Either replace `return self.value` with `print(self.value)` # or add a print statement **above** `return` as `print(self.value)`. -# b) Remove `return(self.value)` and replace it with `print(self.value)` \ No newline at end of file +# b) Remove `return(self.value)` and replace it with `print(self.value)` diff --git a/02-encapsulation-2.py b/01-encapsulation/02-encapsulation-2.py similarity index 90% rename from 02-encapsulation-2.py rename to 01-encapsulation/02-encapsulation-2.py index 4b6e824..4ffc1b2 100644 --- a/02-encapsulation-2.py +++ b/01-encapsulation/02-encapsulation-2.py @@ -17,12 +17,13 @@ def set_val(self, val): def get_val(self): print(self.value) + a = MyClass() b = MyClass() a.set_val(10) b.set_val(1000) -a.value = 100 # <== Overriding `set_value` directly +a.value = 100 # <== Overriding `set_value` directly # <== ie.. Breaking encapsulation a.get_val() diff --git a/03-encapsulation-3.py b/01-encapsulation/03-encapsulation-3.py similarity index 95% rename from 03-encapsulation-3.py rename to 01-encapsulation/03-encapsulation-3.py index 5411ee0..fa69858 100644 --- a/03-encapsulation-3.py +++ b/01-encapsulation/03-encapsulation-3.py @@ -35,6 +35,7 @@ def increment_val(self): self.val = self.val + 1 print(self.val) + a = MyInteger() a.set_val(10) a.get_val() @@ -51,6 +52,6 @@ def increment_val(self): # Trying to break encapsulation in a new instance with a str b = MyInteger() b.val = "MyString" # <== Breaking encapsulation, works fine -b.get_val() # <== Prints the val set by breaking encap +b.get_val() # <== Prints the val set by breaking encap b.increment_val() # This will fail, since str + int wont work print("\n") diff --git a/04-init_constructor-1.py b/02-init_constructor/04-init_constructor-1.py similarity index 99% rename from 04-init_constructor-1.py rename to 02-init_constructor/04-init_constructor-1.py index 12e1fb4..0d56808 100644 --- a/04-init_constructor-1.py +++ b/02-init_constructor/04-init_constructor-1.py @@ -22,6 +22,7 @@ def increment(self): self.val = self.val + 1 print(self.val) + dd = MyNum() dd.increment() # will print 1 dd.increment() # will print 2 diff --git a/05-init_constructor-2.py b/02-init_constructor/05-init_constructor-2.py similarity index 84% rename from 05-init_constructor-2.py rename to 02-init_constructor/05-init_constructor-2.py index 8207765..8cd8263 100644 --- a/05-init_constructor-2.py +++ b/02-init_constructor/05-init_constructor-2.py @@ -20,5 +20,5 @@ def increment(self): a = MyNum(10) -a.increment() # This should print 11 -a.increment() # This should print 12 +a.increment() # This should print 11 +a.increment() # This should print 12 diff --git a/06-class-attributes-1.py b/03-class_attributes/06-class-attributes-1.py similarity index 82% rename from 06-class-attributes-1.py rename to 03-class_attributes/06-class-attributes-1.py index 8687ac8..2f0566c 100644 --- a/06-class-attributes-1.py +++ b/03-class_attributes/06-class-attributes-1.py @@ -15,10 +15,11 @@ class YourClass(object): def set_val(self): self.insty = 100 + dd = YourClass() -dd.classy # This will fetch the class attribute 10. +dd.classy # This will fetch the class attribute 10. dd.set_val() -dd.insty # This will fetch the instance attribute 100. +dd.insty # This will fetch the instance attribute 100. # Once `dd` is instantiated, we can access both the class and instance # attributes, ie.. dd.classy and dd.insty. diff --git a/07-class-attributes-2.py b/03-class_attributes/07-class-attributes-2.py similarity index 93% rename from 07-class-attributes-2.py rename to 03-class_attributes/07-class-attributes-2.py index 7a6e4d5..f3a8160 100644 --- a/07-class-attributes-2.py +++ b/03-class_attributes/07-class-attributes-2.py @@ -20,11 +20,12 @@ class YourClass(object): classy = "class value" + dd = YourClass() print(dd.classy) # < This should return the string "class value" dd.classy = "Instance value" -print(dd.classy) # This should return the string "Instance value" +print(dd.classy) # This should return the string "Instance value" # This will delete the value set for 'dd.classy' in the instance. del dd.classy diff --git a/08-class-instance-attributes-1.py b/03-class_attributes/08-class-instance-attributes-1.py similarity index 99% rename from 08-class-instance-attributes-1.py rename to 03-class_attributes/08-class-instance-attributes-1.py index c0e4cfa..2228c05 100644 --- a/08-class-instance-attributes-1.py +++ b/03-class_attributes/08-class-instance-attributes-1.py @@ -26,6 +26,7 @@ def get_val(self): def get_count(self): print(InstanceCounter.count) + a = InstanceCounter(5) b = InstanceCounter(10) c = InstanceCounter(15) diff --git a/09-inheritance-1.py b/04-inheritance/09-inheritance-1.py similarity index 92% rename from 09-inheritance-1.py rename to 04-inheritance/09-inheritance-1.py index d60a0ce..17b0d10 100644 --- a/09-inheritance-1.py +++ b/04-inheritance/09-inheritance-1.py @@ -22,6 +22,7 @@ class Time(Date): def get_time(self): print("07:00:00") + # Creating an instance from `Date` dt = Date() dt.get_date() # Accesing the `get_date()` method of `Date` @@ -29,6 +30,6 @@ def get_time(self): # Creating an instance from `Time`. tm = Time() -tm.get_time() # Accessing the `get_time()` method from `Time`. +tm.get_time() # Accessing the `get_time()` method from `Time`. # Accessing the `get_date() which is defined in the parent class `Date`. tm.get_date() diff --git a/10-inheritance-2.py b/04-inheritance/10-inheritance-2.py similarity index 98% rename from 10-inheritance-2.py rename to 04-inheritance/10-inheritance-2.py index 708bf24..c8b8819 100644 --- a/10-inheritance-2.py +++ b/04-inheritance/10-inheritance-2.py @@ -16,6 +16,7 @@ # But the instance created from 'Cat' cannot access the attributes # within the 'Dog' class, and vice versa. + class Animal(object): def __init__(self, name): self.name = name @@ -23,14 +24,17 @@ def __init__(self, name): def eat(self, food): print("%s is eating %s" % (self.name, food)) + class Dog(Animal): def fetch(self, thing): print("%s goes after the %s" % (self.name, thing)) + class Cat(Animal): def swatstring(self): print("%s shred the string!" % self.name) + d = Dog("Roger") c = Cat("Fluffy") @@ -44,4 +48,4 @@ def swatstring(self): # have access to the other class. c.fetch("frizbee") -d.swatstring() \ No newline at end of file +d.swatstring() diff --git a/13-inheriting-init-constructor-1.py b/04-inheritance/13-inheriting-init-constructor-1.py similarity index 80% rename from 13-inheriting-init-constructor-1.py rename to 04-inheritance/13-inheriting-init-constructor-1.py index 1650fd5..505e416 100644 --- a/13-inheriting-init-constructor-1.py +++ b/04-inheritance/13-inheriting-init-constructor-1.py @@ -14,8 +14,9 @@ def __init__(self, name): class Dog(Animal): def fetch(self, thing): - print('%s goes after the %s' % (self.name, thing)) + print("%s goes after the %s" % (self.name, thing)) + d = Dog("Roger") -print "The dog's name is", d.name +print("The dog's name is", d.name) d.fetch("frizbee") diff --git a/14-multiple-inheritance-1.py b/04-inheritance/14-multiple-inheritance-1.py similarity index 100% rename from 14-multiple-inheritance-1.py rename to 04-inheritance/14-multiple-inheritance-1.py index 5d32afd..6ea936a 100644 --- a/14-multiple-inheritance-1.py +++ b/04-inheritance/14-multiple-inheritance-1.py @@ -24,7 +24,6 @@ class A(object): - def dothis(self): print("doing this in A") @@ -41,6 +40,7 @@ def dothis(self): class D(B, C): pass + d_instance = D() d_instance.dothis() # <== This should print from class A. diff --git a/15-multiple-inheritance-2.py b/04-inheritance/15-multiple-inheritance-2.py similarity index 100% rename from 15-multiple-inheritance-2.py rename to 04-inheritance/15-multiple-inheritance-2.py index 01d561f..3d35972 100644 --- a/15-multiple-inheritance-2.py +++ b/04-inheritance/15-multiple-inheritance-2.py @@ -21,7 +21,6 @@ class A(object): - def dothat(self): print("Doing this in A") @@ -31,7 +30,6 @@ class B(A): class C(object): - def dothis(self): print("\nDoing this in C") @@ -39,8 +37,10 @@ def dothis(self): class D(B, C): """Multiple Inheritance, D inheriting from both B and C""" + pass + d_instance = D() d_instance.dothis() diff --git a/16-multiple-inheritance-3.py b/04-inheritance/16-multiple-inheritance-3.py similarity index 100% rename from 16-multiple-inheritance-3.py rename to 04-inheritance/16-multiple-inheritance-3.py index 036b875..f5b82c0 100644 --- a/16-multiple-inheritance-3.py +++ b/04-inheritance/16-multiple-inheritance-3.py @@ -31,7 +31,6 @@ class A(object): - def dothis(self): print("doing this in A") @@ -48,6 +47,7 @@ def dothis(self): class D(B, C): pass + d_instance = D() d_instance.dothis() diff --git a/11-polymorphism-1.py b/05-polymorphism/11-polymorphism-1.py similarity index 75% rename from 11-polymorphism-1.py rename to 05-polymorphism/11-polymorphism-1.py index a695822..d43ec67 100644 --- a/11-polymorphism-1.py +++ b/05-polymorphism/11-polymorphism-1.py @@ -21,30 +21,28 @@ class Animal(object): - def __init__(self, name): self.name = name def eat(self, food): - print('{0} eats {1}'.format(self.name, food)) + print("{0} eats {1}".format(self.name, food)) class Dog(Animal): - def fetch(self, thing): - print('{0} goes after the {1}!'.format(self.name, thing)) + print("{0} goes after the {1}!".format(self.name, thing)) def show_affection(self): - print('{0} wags tail'.format(self.name)) + print("{0} wags tail".format(self.name)) class Cat(Animal): - def swatstring(self): - print('{0} shreds more string'.format(self.name)) + print("{0} shreds more string".format(self.name)) def show_affection(self): - print('{0} purrs'.format(self.name)) + print("{0} purrs".format(self.name)) + -for a in (Dog('Rover'), Cat('Fluffy'), Cat('Lucky'), Dog('Scout')): +for a in (Dog("Rover"), Cat("Fluffy"), Cat("Lucky"), Dog("Scout")): a.show_affection() diff --git a/12-polymorphism-2.py b/05-polymorphism/12-polymorphism-2.py similarity index 95% rename from 12-polymorphism-2.py rename to 05-polymorphism/12-polymorphism-2.py index 80eddbb..e869cc8 100644 --- a/12-polymorphism-2.py +++ b/05-polymorphism/12-polymorphism-2.py @@ -24,4 +24,4 @@ print(len(text)) print(len("Hello")) -print(len({'a': 1, 'b': 2, 'c': 3})) +print(len({"a": 1, "b": 2, "c": 3})) diff --git a/19-decorators-1.py b/06-decorators/19-decorators-1.py similarity index 78% rename from 19-decorators-1.py rename to 06-decorators/19-decorators-1.py index 9a9244c..96c2de1 100644 --- a/19-decorators-1.py +++ b/06-decorators/19-decorators-1.py @@ -30,22 +30,24 @@ # function you're actually executing. -def my_decorator(my_function): # <-- (4) - def inner_decorator(): # <-- (5) +def my_decorator(my_function): # <-- (4) + def inner_decorator(): # <-- (5) print("This happened before!") # <-- (6) - my_function() # <-- (7) - print("This happens after ") # <-- (10) - print("This happened at the end!") # <-- (11) + my_function() # <-- (7) + print("This happens after ") # <-- (10) + print("This happened at the end!") # <-- (11) + return inner_decorator # return None -@my_decorator # <-- (3) -def my_decorated(): # <-- (2) <-- (8) - print("This happened!") # <-- (9) +@my_decorator # <-- (3) +def my_decorated(): # <-- (2) <-- (8) + print("This happened!") # <-- (9) + -if __name__ == '__main__': - my_decorated() # <-- (1) +if __name__ == "__main__": + my_decorated() # <-- (1) # This prints: # # python 19-decorators-1.py diff --git a/20-decorators-2.py b/06-decorators/20-decorators-2.py similarity index 99% rename from 20-decorators-2.py rename to 06-decorators/20-decorators-2.py index 9d3e8e1..590d7cd 100644 --- a/20-decorators-2.py +++ b/06-decorators/20-decorators-2.py @@ -18,6 +18,7 @@ def inner_decorator(): print(datetime.datetime.utcnow()) inner() print(datetime.datetime.utcnow()) + return inner_decorator @@ -25,6 +26,7 @@ def inner_decorator(): def decorated(): print("This happened!") + if __name__ == "__main__": decorated() diff --git a/21-decorators-3.py b/06-decorators/21-decorators-3.py similarity index 99% rename from 21-decorators-3.py rename to 06-decorators/21-decorators-3.py index d7b4899..f8e45fe 100644 --- a/21-decorators-3.py +++ b/06-decorators/21-decorators-3.py @@ -21,6 +21,7 @@ def inner_decorator(num_copy): print(datetime.datetime.utcnow()) inner(int(num_copy) + 1) print(datetime.datetime.utcnow()) + return inner_decorator @@ -28,6 +29,7 @@ def inner_decorator(num_copy): def decorated(number): print("This happened : " + str(number)) + if __name__ == "__main__": decorated(5) diff --git a/22-decorators-4.py b/06-decorators/22-decorators-4.py similarity index 99% rename from 22-decorators-4.py rename to 06-decorators/22-decorators-4.py index 9399fd3..4ed2aa1 100644 --- a/22-decorators-4.py +++ b/06-decorators/22-decorators-4.py @@ -19,6 +19,7 @@ def decorator(inner): def inner_decorator(*args, **kwargs): print(args, kwargs) + return inner_decorator @@ -26,6 +27,7 @@ def inner_decorator(*args, **kwargs): def decorated(string_args): print("This happened : " + string_args) + if __name__ == "__main__": decorated("Hello, how are you?") diff --git a/23-decorators-5.py b/06-decorators/23-decorators-5.py similarity index 99% rename from 23-decorators-5.py rename to 06-decorators/23-decorators-5.py index eed3a74..daf4ff5 100644 --- a/23-decorators-5.py +++ b/06-decorators/23-decorators-5.py @@ -14,6 +14,7 @@ def inner(*args, **kwargs): return func_name(*args, **kwargs) except Exception: print("An exception was thrown : ", Exception) + return inner @@ -22,4 +23,5 @@ def inner(*args, **kwargs): def divide(x, y): return x / y + print(divide(8, 0)) diff --git a/24-decorators-6.py b/06-decorators/24-decorators-6.py similarity index 99% rename from 24-decorators-6.py rename to 06-decorators/24-decorators-6.py index 9519059..c96e2e8 100644 --- a/24-decorators-6.py +++ b/06-decorators/24-decorators-6.py @@ -5,6 +5,7 @@ def decorator(inner): def inner_decorator(*args, **kwargs): print("This function takes " + str(len(args)) + " arguments") inner(*args) + return inner_decorator diff --git a/25-decorators-7.py b/06-decorators/25-decorators-7.py similarity index 99% rename from 25-decorators-7.py rename to 06-decorators/25-decorators-7.py index b41569d..3b18c99 100644 --- a/25-decorators-7.py +++ b/06-decorators/25-decorators-7.py @@ -15,6 +15,7 @@ def double(my_func): def inner_func(a, b): return 2 * my_func(a, b) + return inner_func diff --git a/26-class-decorators.py b/06-decorators/26-class-decorators.py similarity index 93% rename from 26-class-decorators.py rename to 06-decorators/26-class-decorators.py index ba7cfd8..0f590ba 100644 --- a/26-class-decorators.py +++ b/06-decorators/26-class-decorators.py @@ -9,7 +9,7 @@ # But decorators can be applied to Classes as well. # This example deals with class decorators. -# NOTE: If you are creating a decorator for a class, you'll it +# NOTE: If you are creating a decorator for a class, you'll it # to return a Class. # NOTE: Similarly, if you are creating a decorator for a function, @@ -20,6 +20,7 @@ def honirific(cls): class HonirificCls(cls): def full_name(self): return "Dr. " + super(HonirificCls, self).full_name() + return HonirificCls @@ -32,6 +33,7 @@ def __init__(self, first_name, last_name): def full_name(self): return " ".join([self.first_name, self.last_name]) + result = Name("Vimal", "A.R").full_name() print("Full name: {0}".format(result)) diff --git a/17-instance_methods-1.py b/07-static_class_instance_methods/17-instance_methods-1.py similarity index 99% rename from 17-instance_methods-1.py rename to 07-static_class_instance_methods/17-instance_methods-1.py index 179f6b1..709670f 100644 --- a/17-instance_methods-1.py +++ b/07-static_class_instance_methods/17-instance_methods-1.py @@ -11,6 +11,7 @@ class A(object): def method(*argv): return argv + a = A() print(a.method) diff --git a/18-instance_methods-2.py b/07-static_class_instance_methods/18-instance_methods-2.py similarity index 99% rename from 18-instance_methods-2.py rename to 07-static_class_instance_methods/18-instance_methods-2.py index 572e279..27b9923 100644 --- a/18-instance_methods-2.py +++ b/07-static_class_instance_methods/18-instance_methods-2.py @@ -42,6 +42,7 @@ def get_val(self): def get_count(self): return InstanceCounter.count + a = InstanceCounter(5) b = InstanceCounter(10) c = InstanceCounter(15) diff --git a/27-classmethod-1.py b/07-static_class_instance_methods/27-classmethod-1.py similarity index 97% rename from 27-classmethod-1.py rename to 07-static_class_instance_methods/27-classmethod-1.py index 37b4040..f5536f8 100644 --- a/27-classmethod-1.py +++ b/07-static_class_instance_methods/27-classmethod-1.py @@ -22,7 +22,7 @@ # NOTE : For the class MyClass: # MyClass is the class itself -# MyClass() is an instance +# MyClass() is an instance class MyClass(object): diff --git a/28-classmethod-2.py b/07-static_class_instance_methods/28-classmethod-2.py similarity index 99% rename from 28-classmethod-2.py rename to 07-static_class_instance_methods/28-classmethod-2.py index b557f8d..5058c07 100644 --- a/28-classmethod-2.py +++ b/07-static_class_instance_methods/28-classmethod-2.py @@ -32,6 +32,7 @@ def get_val(self): def get_count(cls): return cls.count + object_1 = MyClass(10) print("\nValue of object : %s" % object_1.get_val()) print(MyClass.get_count()) diff --git a/29-staticmethod-1.py b/07-static_class_instance_methods/29-staticmethod-1.py similarity index 100% rename from 29-staticmethod-1.py rename to 07-static_class_instance_methods/29-staticmethod-1.py diff --git a/30-staticmethod-2.py b/07-static_class_instance_methods/30-staticmethod-2.py similarity index 99% rename from 30-staticmethod-2.py rename to 07-static_class_instance_methods/30-staticmethod-2.py index f36685c..af3bc6b 100644 --- a/30-staticmethod-2.py +++ b/07-static_class_instance_methods/30-staticmethod-2.py @@ -28,6 +28,7 @@ def __init__(self, name): def status(): print("The total number of instances are ", MyClass.count) + print(MyClass.count) my_func_1 = MyClass("MyClass 1") diff --git a/31-magicmethods-1.py b/07-static_class_instance_methods/31-magicmethods-1.py similarity index 99% rename from 31-magicmethods-1.py rename to 07-static_class_instance_methods/31-magicmethods-1.py index f76a3e8..b9794c5 100644 --- a/31-magicmethods-1.py +++ b/07-static_class_instance_methods/31-magicmethods-1.py @@ -10,7 +10,6 @@ class PrintList(object): - def __init__(self, my_list): self.mylist = my_list diff --git a/32-magicmethods-2.py b/07-static_class_instance_methods/32-magicmethods-2.py similarity index 100% rename from 32-magicmethods-2.py rename to 07-static_class_instance_methods/32-magicmethods-2.py diff --git a/34-abstractclasses-1.py b/08-abstract_classes/34-abstractclasses-1.py similarity index 99% rename from 34-abstractclasses-1.py rename to 08-abstract_classes/34-abstractclasses-1.py index 24ccbc7..4daed28 100644 --- a/34-abstractclasses-1.py +++ b/08-abstract_classes/34-abstractclasses-1.py @@ -33,13 +33,13 @@ def set_val(self, val): def get_val(self): return + # Abstract Base Class defined above ^^^ # Custom class inheriting from the above Abstract Base Class, below class MyClass(My_ABC_Class): - def set_val(self, input): self.val = input @@ -52,6 +52,7 @@ def hello(self): print("\nCalling the hello() method") print("I'm *not* part of the Abstract Methods defined in My_ABC_Class()") + my_class = MyClass() my_class.set_val(10) diff --git a/35-abstractclasses-2.py b/08-abstract_classes/35-abstractclasses-2.py similarity index 95% rename from 35-abstractclasses-2.py rename to 08-abstract_classes/35-abstractclasses-2.py index 31d1ca7..6275e4b 100644 --- a/35-abstractclasses-2.py +++ b/08-abstract_classes/35-abstractclasses-2.py @@ -19,7 +19,7 @@ # methods of their own, but *should always* implement the methods defined in # the parent ABC Class. -# NOTE: This code will error out. This is an example on what +# NOTE: This code will error out. This is an example on what # happens when a child class doesn't implement the abstract methods # defined in the Parent Class. @@ -37,13 +37,13 @@ def set_val(self, val): def get_val(self): return + # Abstract Base Class defined above ^^^ # Custom class inheriting from the above Abstract Base Class, below class MyClass(My_ABC_Class): - def set_val(self, input): self.val = input @@ -51,6 +51,7 @@ def hello(self): print("\nCalling the hello() method") print("I'm *not* part of the Abstract Methods defined in My_ABC_Class()") + my_class = MyClass() my_class.set_val(10) diff --git a/36-abstractclasses-3.py b/08-abstract_classes/36-abstractclasses-3.py similarity index 95% rename from 36-abstractclasses-3.py rename to 08-abstract_classes/36-abstractclasses-3.py index 70532bc..f1c33ab 100644 --- a/36-abstractclasses-3.py +++ b/08-abstract_classes/36-abstractclasses-3.py @@ -19,7 +19,7 @@ # methods of their own, but *should always* implement the methods defined in # the parent ABC Class. -# NOTE: This code will error out. This is an example on what +# NOTE: This code will error out. This is an example on what # happens when a child class doesn't implement the abstract methods # defined in the Parent Class. @@ -37,13 +37,13 @@ def set_val(self, val): def get_val(self): return + # Abstract Base Class defined above ^^^ # Custom class inheriting from the above Abstract Base Class, below class MyClass(My_ABC_Class): - def set_val(self, input): self.val = input @@ -51,6 +51,7 @@ def hello(self): print("\nCalling the hello() method") print("I'm *not* part of the Abstract Methods defined in My_ABC_Class()") + my_class = My_ABC_Class() my_class.set_val(10) diff --git a/37-method-overloading-1.py b/09-method_overloading/37-method-overloading-1.py similarity index 93% rename from 37-method-overloading-1.py rename to 09-method_overloading/37-method-overloading-1.py index 1a3b0bc..1988f9f 100644 --- a/37-method-overloading-1.py +++ b/09-method_overloading/37-method-overloading-1.py @@ -6,12 +6,12 @@ # http://shop.oreilly.com/product/0636920040057.do # Chapter 24 : Method Overloading - Extending and Providing -# This code is an example on how we can extend a method inherited by -# a child class from the Parent class. +# This code is an example on how we can extend a method inherited by +# a child class from the Parent class. # 1) We have defined `MyClass()` as an abstract class, # and it has three methods, my_set_val(), my_get_val(), and print_doc(). -# 2) MyChildClass() inherits from MyClass() +# 2) MyChildClass() inherits from MyClass() # 3) MyChildClass() extends the parent's my_set_val() method # by it's own my_set_val() method. It checks for the input, # checks if it's an integer, and then calls the my_set_val() @@ -40,7 +40,6 @@ def print_doc(self): class MyChildClass(MyClass): - def my_set_val(self, value): if not isinstance(value, int): value = 0 @@ -49,8 +48,8 @@ def my_set_val(self, value): def print_doc(self): print("Documentation for MyChild Class") + my_instance = MyChildClass() my_instance.my_set_val(100) print(my_instance.my_get_val()) print(my_instance.print_doc()) - diff --git a/38-method-overloading-2.py b/09-method_overloading/38-method-overloading-2.py similarity index 84% rename from 38-method-overloading-2.py rename to 09-method_overloading/38-method-overloading-2.py index 94a0a09..3051114 100644 --- a/38-method-overloading-2.py +++ b/09-method_overloading/38-method-overloading-2.py @@ -41,5 +41,8 @@ def set_val(self, value): self.vallist.append(value) def showdoc(self): - print("GetSetList object, len {0}, store history of values set".format( - len(self.vallist))) + print( + "GetSetList object, len {0}, store history of values set".format( + len(self.vallist) + ) + ) diff --git a/39-method-overloading-3.py b/09-method_overloading/39-method-overloading-3.py similarity index 92% rename from 39-method-overloading-3.py rename to 09-method_overloading/39-method-overloading-3.py index 3e364ee..1656712 100644 --- a/39-method-overloading-3.py +++ b/09-method_overloading/39-method-overloading-3.py @@ -9,7 +9,6 @@ class MyList(list): - def __getitem__(self, index): if index == 0: raise IndexError @@ -24,15 +23,16 @@ def __setitem__(self, index, value): index -= 1 list.__setitem__(self, index, value) -x = MyList(['a', 'b', 'c']) + +x = MyList(["a", "b", "c"]) print(x) print("-" * 10) -x.append('d') +x.append("d") print(x) print("-" * 10) -x.__setitem__(4, 'e') +x.__setitem__(4, "e") print(x) print("-" * 10) diff --git a/40-super-1.py b/10-super/40-super-1.py similarity index 99% rename from 40-super-1.py rename to 10-super/40-super-1.py index 7e1f472..4eeea91 100644 --- a/40-super-1.py +++ b/10-super/40-super-1.py @@ -10,19 +10,17 @@ class MyClass(object): - def func(self): print("I'm being called from the Parent class") class ChildClass(MyClass): - def func(self): print("I'm actually being called from the Child class") print("But...") # Calling the `func()` method from the Parent class. super(ChildClass, self).func() + my_instance_2 = ChildClass() my_instance_2.func() - diff --git a/41-super-2.py b/10-super/41-super-2.py similarity index 100% rename from 41-super-2.py rename to 10-super/41-super-2.py index c53b339..8770092 100644 --- a/41-super-2.py +++ b/10-super/41-super-2.py @@ -27,7 +27,6 @@ def print_doc(self): class MyChildClass(MyClass): - def my_set_val(self, value): if not isinstance(value, int): value = 0 @@ -36,6 +35,7 @@ def my_set_val(self, value): def print_doc(self): print("Documentation for MyChild Class") + my_instance = MyChildClass() my_instance.my_set_val(100) print(my_instance.my_get_val()) diff --git a/42-super-3.py b/10-super/42-super-3.py similarity index 99% rename from 42-super-3.py rename to 10-super/42-super-3.py index c194f96..73d512a 100644 --- a/42-super-3.py +++ b/10-super/42-super-3.py @@ -31,5 +31,6 @@ def foo(self): print("D") super(D, self).foo() + d = D() d.foo() diff --git a/33-attribute-encapsulation-1.py b/33-attribute-encapsulation-1.py deleted file mode 100644 index e69de29..0000000 diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..034e848 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 5.1.x | :white_check_mark: | +| 5.0.x | :x: | +| 4.0.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc.