Instructor Notes
This is a placeholder file. Please add content here.
What is QMI?
'Hello World'
Instructor Note
Also a nice info to view now is
Controlling an instrument
Instructor Note
A bit shorter listing of the attributes of the object, you can use
but it is not easy to read and has also internal and non-RPC variable and callable methods present.
You can also get “help” of any method present. Try:
Configuring and logging
Accessing an instrument remotely
Create a task and a 'service'
Open-source vs internal code
Good coding practises: MyPy
Instructor Note
The MyPy output tells us the typing of variable debts
is
wrong: it is annotated as a str but the value is a
float. The call to summer_fun
has also problems.
This is because input
call returns always a string. The 4th
line of Mypy error now shows that we cannot add together
debts
and a supposed int return value from
summer_fun
. The last line means that we cannot take a
‘minus’ of a string.
Instructor Note
OUTPUT
mypy_exercise.py:8: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
mypy_exercise.py:9: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
mypy_exercise.py:10: error: Argument 1 to "summer_fun" has incompatible type "str"; expected "int" [arg-type]
mypy_exercise.py:10: error: Argument 2 to "summer_fun" has incompatible type "str"; expected "int" [arg-type]
mypy_exercise.py:11: error: Incompatible types in assignment (expression has type "float", variable has type "int") [assignment]
Found 5 errors in 1 file (checked 1 source file)
The variables alice_has
and bob_has
are
still typed as the original type, str even after casting.
Instead of changing the variable assignment, MyPy warns that you are
doing something potentially harmful and errors out. Therefore the
summer_fun
input argument errors did not go away, either.
The last error is also new: Now Mypy complains that,
left_sum
being annotated as an int, the sum of
debts
and alice_and_bob_have
will be
float.
Instructor Note
Mypy says now Success: no issues found in 1 source file
.
Also, the code will run if the user inputs whole numbers. Notably, the
print-outs also work, giving the values with two decimal accuracy like
indicated by the :0.2f
formatter in the strings. But all is
not well here. What if you want to use a decimal value for ‘money’, like
30.1? You get an exception out:
OUTPUT
Traceback (most recent call last):
File "mypy_exercise.py", line 8, in <module>
alice_and_bob_have = summer_fun(int(alice_has), int(bob_has))
~~~^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '30.1'