Terminal setup using ZSH, Prezto and Starship on MacOS

ZSH installation

Starting with Catalina the default shell was changed to zsh. You can verify your current shell using:

 echo $SHELL

If it's not zsh for you, you can install it using Homebrew

brew install zsh

Once installed we need to make zsh the default shell using:

chsh -s /bin/zsh

Prezto installation

Prezto is a configuration framework for zsh. Another well known alternative is Oh My Zsh.

I was using Oh My Zsh previously but it had performance issues and switching to Prezto has helped with the performance issues. Oh My Zsh has a much bigger community and receives regular updates and is bit more beginner friendly.

Before installing make sure to make a back of your .zshrc file if you had one already …

Become a pdb power-user

This is an explanatory article related to my talk at MUPy  --  Become a pdb power-user.

This article was originally published on Medium

What's pdb?

pdb is a module from Python's standard library that allows us to do things like:

  • Stepping through source code
  • Setting conditional breakpoints
  • Inspecting stack trace
  • Viewing source code
  • Running Python code in a context
  • Post-mortem debugging

Why pdb?

It is not necessary to use pdb all the time, sometimes we can get away with simple print statements or logging.

But these other approaches are most of the time not good enough and don't give us enough control while debugging. Plus after debugging we also have to take care of removing the `print`` statements that we had added to our program just for debugging …

Handling missing keys in str.format_map properly

str.format_map was introduced in Python 3.2, it allows users to a pass a dictionary instead of individual keyword arguments. This can be very useful in case some of the format arguments are missing from the dictionary, take this example from docs:

class Default(dict):
    def __missing__(self, key):
        return key

print ('{name} was born in {country}'.format_map(Default(name='Guido'))) 
# Guido was born in country

But this fails:

>>> print ('{name} was born in {country.state}'.format_map(Default(name='Guido')))
Traceback (most recent call last):
  File "<ipython-input-324-1012aa68ba8d>", line 1, in <module>
    print ('{name} was born in {country.state}'.format_map(Default(name='Guido')))
AttributeError: 'str' object has no attribute 'state'

That is obvious because we are returning a string from __missing__ and that string doesn't have any …