Skip to content

madison-python/welcome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

113 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to MadPy!


The MadPy Magpie

Organizers

Ed Rogers David Hoese Josh Karpel

Ed Rogers

David Hoese

Josh Karpel

Code of Conduct

MadPy is a community group and open to all experience levels. We are committed to a safe, professional environment

Our Commitment to You

We are enthusiastically focused on improving our event and making it a place that is welcoming to all. All reports will be taken seriously, handled respectfully, and dealt with in a timely manner.

Learn more about the MadPy Code of Conduct:

https://github.com/madison-python/code-of-conduct

Python Warm-Up

A get function with a default:

madpy_menu = {
    "pizza": "Ian's",
    "beverage": "Sprite",
}
def get_menu_item(key, default=None):
    value = madpy_menu.get(key)
    if value is None:
        return default
    return value
get_menu_item("pizza")
"Ian's"
get_menu_item("salad", default="Sorry, not tonight!")
'Sorry, not tonight!'

Trouble with the get function:

madpy_menu = {
    "pizza": "Ian's",
    "beverage": "Sprite",
    "dessert": None,
}
def get_menu_item(key, default=None):
    value = madpy_menu.get(key)
    if value is None:
        return default
    return value
get_menu_item("salad", default="Sorry, not tonight!")
'Sorry, not tonight!'
get_menu_item("dessert", default="Sorry, not tonight!")
'Sorry, not tonight!'

Can't distinguish between not being on the menu, and being on the menu and None-valued!

Using a "sentinel" value

madpy_menu = {
    "pizza": "Ian's",
    "beverage": "Sprite",
    "dessert": None,
}
MISSING = object()

def get_menu_item(key, default=None):
    value = madpy_menu.get(key, MISSING)
    if value is MISSING:
        return default
    return value
get_menu_item("salad", default="Sorry, not tonight!")
'Sorry, not tonight!'
get_menu_item("dessert", default="Sorry, not tonight!") is None
True
print(MISSING)
<object object at 0x7bf5c437d710>

Can we make it prettier?

madpy_menu = {
    "pizza": "Ian's",
    "beverage": "Sprite",
    "dessert": None,
}
from enum import StrEnum

class Missing(StrEnum):
    MISSING = "MISSING"

def get_menu_item(key, default=None):
    value = madpy_menu.get(key, Missing.MISSING)
    if value is Missing.MISSING:
        return default
    return value
get_menu_item("salad", default="Sorry, not tonight!")
'Sorry, not tonight!'
get_menu_item("dessert", default="Sorry, not tonight!") is None
True
print(Missing.MISSING)
MISSING

New in Python 3.15 (to be released in October 2026)

from sys import version

print(version)
3.15.0b2 (main, Jun  2 2026, 22:26:04) [Clang 22.1.3 ]
from builtins import sentinel

MISSING = sentinel("MISSING")
madpy_menu = {
    "pizza": "Ian's",
    "beverage": "Sprite",
    "dessert": None,
}
MISSING = sentinel("MISSING")

def get_menu_item(key, default=None):
    value = madpy_menu.get(key, MISSING)
    if value is MISSING:
        return default
    return value
get_menu_item("salad", default="Sorry, not tonight!")
'Sorry, not tonight!'
get_menu_item("dessert", default="Sorry, not tonight!") is None
True
print(MISSING)
MISSING

Want more MadPy?

MadPymadpy.com
Meetupmeetup.com/madpython
GitHubgithub.com/madison-python
Mastodonfosstodon.org/@madpy
Slackslack.madpy.com
LinkedInlinkedin.com/company/madpy

The Best Way to Help MadPy

Talk to your employer about Sponsorship!

Logo for the MadPy talk

About

Welcome to Madpy!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors