16.12. OOP Recap

16.12.1. Atlassian Python API

$ pip install atlassian-python-api
>>> 
... from atlassian import Jira
...
...
... jira = Jira(
...     url='https://example.com:8080',
...     username='myusername',
...     password='mypassword')
...
... JQL = 'project = DEMO AND status IN ("To Do", "In Progress") ORDER BY issuekey'
...
... result = jira.jql(JQL)
... print(result)
>>> 
... from atlassian import Confluence
...
...
... confluence = Confluence(
...     url='https://example.com:8090',
...     username='myusername',
...     password='mypassword')
...
... result = confluence.create_page(
...     space='DEMO',
...     title='This is the title',
...     body='This is the body. You can use <strong>HTML tags</strong>!')
...
... print(result)

16.12.2. Assignments

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Class
# - Difficulty: easy
# - Lines: 4
# - Minutes: 2

# %% English
# 1. Define class `Astronaut`
# 2. Define class `SpaceAgency`
# 3. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj klasę `Astronaut`
# 2. Zdefiniuj klasę `SpaceAgency`
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> from inspect import isclass

>>> assert isclass(Astronaut)
>>> assert isclass(SpaceAgency)
"""

# Define class `Astronaut`
# type: type
...

# Define class `SpaceAgency`
# type: type
...


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Instance
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Create instance `mark` of a class `Astronaut`
# 2. Create instance `nasa` of a class `SpaceAgency`
# 3. Run doctests - all must succeed

# %% Polish
# 1. Stwórz instancję `mark` klasy `Astronaut`
# 2. Stwórz instancję `nasa` klasy `SpaceAgency`
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> from inspect import isclass

>>> assert isclass(Astronaut)
>>> assert isclass(SpaceAgency)
>>> assert isinstance(mark, Astronaut)
>>> assert isinstance(nasa, SpaceAgency)
"""

class Astronaut:
    pass


class SpaceAgency:
    pass


# Create instance `mark` of a class `Astronaut`
# type: Astronaut
...

# Create instance `nasa` of a class `SpaceAgency`
# type: SpaceAgency
...


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Fields
# - Difficulty: easy
# - Lines: 6
# - Minutes: 3

# %% English
# 1. Modify code below
# 2. Set attibutes of mark and nasa instances to model the data:
#    - Mark, USA, 1969-07-21
#    - Nasa, USA, 1969-07-21
# 3. Run doctests - all must succeed

# %% Polish
# 1. Zmodyfikuj kod poniżej
# 2. Ustaw atrybuty instancji mark i nasa by zamodelować dane:
#    - Mark, USA, 1969-07-21
#    - Nasa, USA, 1969-07-21
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> assert isinstance(mark, Astronaut)
>>> assert isinstance(nasa, SpaceAgency)
>>> assert 'Mark' in vars(mark).values()
>>> assert 'USA' in vars(mark).values()
>>> assert '1969-07-21' in vars(mark).values()
>>> assert 'Nasa' in vars(nasa).values()
>>> assert 'USA' in vars(nasa).values()
>>> assert '1969-07-21' in vars(nasa).values()
"""


class Astronaut:
    pass


class SpaceAgency:
    pass


mark = Astronaut()
nasa = SpaceAgency()

# Mark, USA, 1969-07-21
# Nasa, USA, 1969-07-21


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Vars
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Define `result_mark: dict[str,str]`
#    with all attributes and values of `mark` object
# 2. Define `result_nasa: dict[str,str]`
#    with all attributes and values of `nasa` object
# 3. Use `vars()`
# 4. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result_mark: dict[str,str]`
#    z wszystkimi atrybutami i wartościami obiektu `mark`
# 2. Zdefiniuj `result_nasa: dict[str,str]`
#    z wszystkimi atrybutami i wartościami obiektu `nasa`
# 3. Użyj `vars()`
# 4. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> assert type(result_mark) is dict
>>> assert type(result_nasa) is dict

>>> result_mark
{'name': 'Mark', 'country': 'USA', 'date': '1969-07-21'}

>>> result_nasa
{'name': 'Nasa', 'country': 'USA', 'date': '1969-07-21'}
"""


class Astronaut:
    pass


class SpaceAgency:
    pass


mark = Astronaut()
nasa = SpaceAgency()

mark.name = 'Mark'
mark.country = 'USA'
mark.date = '1969-07-21'

nasa.name = 'Nasa'
nasa.country = 'USA'
nasa.date = '1969-07-21'


# Dict with all attributes and values of `mark` object
# type: dict[str,str]
result_mark = ...

# Dict with all attributes and values of `nasa` object
# type: dict[str,str]
result_nasa = ...


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Init
# - Difficulty: easy
# - Lines: 8
# - Minutes: 3

# %% English
# 1. Modify code below
# 2. Define method `__init__()` to set attributes:
#    `self.name`, `self.country`, `self.date`
# 3. Attributes must be set from arguments passed at initialization
# 4. Run doctests - all must succeed

# %% Polish
# 1. Zmodyfikuj kod poniżej
# 2. Zdefiniuj metodę `__init__()` aby ustawiała atrybuty:
#    `self.name`, `self.country`, `self.date`
# 3. Atrybuty muszą być ustawiane z argumentów podanych przy inicjalizacji
# 4. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> from inspect import ismethod, signature

>>> mark = Astronaut('Mark', 'USA', '1969-07-21')
>>> nasa = Astronaut('Nasa', 'USA', '1969-07-21')

>>> assert ismethod(mark.__init__)
>>> assert ismethod(nasa.__init__)

>>> signature(Astronaut.__init__)
<Signature (self, name, country, date)>
>>> signature(SpaceAgency.__init__)
<Signature (self, name, country, date)>

>>> signature(mark.__init__)
<Signature (name, country, date)>
>>> signature(nasa.__init__)
<Signature (name, country, date)>
"""


# Define method to set: self.name, self.country, self.date
# Attributes must be set from arguments passed to __init__()
# type: type[Astronaut]
class Astronaut:
    pass


# Define method to set: self.name, self.country, self.date
# Attributes must be set from arguments passed to __init__()
# type: type[Astronaut]
class SpaceAgency:
    pass


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Instantiate
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Modify code below
# 2. Create instances of an `Astronaut` and `SpaceAgency` classes
# 3. Use positional arguments to pass values at the initialization
# 4. Run doctests - all must succeed

# %% Polish
# 1. Zmodyfikuj kod poniżej
# 2. Stwórz instancje klas `Astronaut` i `SpaceAgency`
# 3. Użyj argumentów pozycyjnych do przekazania wartości przy inicjalizacji
# 4. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> assert isinstance(mark, Astronaut)
>>> assert isinstance(nasa, SpaceAgency)
>>> assert 'Mark' in vars(mark).values()
>>> assert 'USA' in vars(mark).values()
>>> assert '1969-07-21' in vars(mark).values()
>>> assert 'Nasa' in vars(nasa).values()
>>> assert 'USA' in vars(nasa).values()
>>> assert '1969-07-21' in vars(nasa).values()
"""


class Astronaut:
    def __init__(self, name, country, date):
        self.name = name
        self.country = country
        self.date = date


class SpaceAgency:
    def __init__(self, name, country, date):
        self.name = name
        self.country = country
        self.date = date


# use positional arguments to create instance with: Mark, USA, 1969-07-21
# type: Astronaut
mark = ...

# use positional arguments to create instance with: Nasa, USA, 1969-07-21
# type: SpaceAgency
nasa = ...


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Recap Instantiate
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Modify code below
# 2. Create instances of an `Astronaut` and `SpaceAgency` classes
# 3. Use keyword arguments to pass values at the initialization
# 4. Run doctests - all must succeed

# %% Polish
# 1. Zmodyfikuj kod poniżej
# 2. Stwórz instancje klas `Astronaut` i `SpaceAgency`
# 3. Użyj argumentów nazwanych do przekazania wartości przy inicjalizacji
# 4. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> assert isinstance(mark, Astronaut)
>>> assert isinstance(nasa, SpaceAgency)
>>> assert 'Mark' in vars(mark).values()
>>> assert 'USA' in vars(mark).values()
>>> assert '1969-07-21' in vars(mark).values()
>>> assert 'Nasa' in vars(nasa).values()
>>> assert 'USA' in vars(nasa).values()
>>> assert '1969-07-21' in vars(nasa).values()
"""


class Astronaut:
    def __init__(self, name, country, date):
        self.name = name
        self.country = country
        self.date = date


class SpaceAgency:
    def __init__(self, name, country, date):
        self.name = name
        self.country = country
        self.date = date


# use keyword arguments to create instance with: Mark, USA, 1969-07-21
# type: Astronaut
mark = ...

# use keyword arguments to create instance with: Nasa, USA, 1969-07-21
# type: SpaceAgency
nasa = ...


# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: OOP Usecase Calculator
# - Difficulty: easy
# - Lines: 13
# - Minutes: 5

# %% English
# 1. Define class `Calculator` with methods:
#    - `__init__()` takes two arguments `a` and `b` and sets them as fields
#    - `add()` which returns sum of `a` and `b`
#    - `sub()` which returns difference of `a` and `b`
#    - `mul()` which returns product of `a` and `b`
#    - `div()` which returns division of `a` and `b`
#    - `mean()` which returns arithemetic average of `a` and `b`
# 3. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj klasę `Calculator` z metodami:
#    - `__init__()` przyjmuje dwa argumenty `a` i `b` i ustawia je jako pola
#    - `add()` która zwraca sumę `a` i `b`
#    - `sub()` która zwraca różnicę `a` i `b`
#    - `mul()` która zwraca iloczyn `a` i `b`
#    - `div()` która zwraca iloraz `a` i `b`
#    - `mean()` która zwraca średnią arytmetyczną `a` i `b`
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> from inspect import isclass, ismethod

>>> assert isclass(Calculator)
>>> calc = Calculator(1, 2)

>>> assert ismethod(calc.add)
>>> assert ismethod(calc.sub)
>>> assert ismethod(calc.mul)
>>> assert ismethod(calc.div)
>>> assert ismethod(calc.mean)

>>> calc.add()
3
>>> calc.sub()
-1
>>> calc.mul()
2
>>> calc.div()
0.5
>>> calc.mean()
1.5
"""

# Define class `Calculator` with methods:
# - `__init__()` takes two arguments `a` and `b` and sets them as fields
# - `add()` which returns sum of `a` and `b`
# - `sub()` which returns difference of `a` and `b`
# - `mul()` which returns product of `a` and `b`
# - `div()` which returns division of `a` and `b`
# - `mean()` which returns arithemetic average of `a` and `b`