Skip to content

Instantly share code, notes, and snippets.

View mpkocher's full-sized avatar

M. Kocher mpkocher

View GitHub Profile
@mpkocher
mpkocher / typeddict_pad.py
Last active October 2, 2019 05:08
Exploring TypedDict in Python 3
#!/usr/bin/env python3
"""Output from mypy 0.711
typeddict_pad.py:28: error: Module 'typing' has no attribute 'TypedDict'; maybe "_TypedDict"?
typeddict_pad.py:28: error: Name 'TypedDict' already defined (possibly by an import)
typeddict_pad.py:90: error: Unsupported operand types for + ("str" and "int")
typeddict_pad.py:107: error: Argument 2 has incompatible type "int"; expected "str"
typeddict_pad.py:110: error: Unsupported operand types for + ("int" and "str")
typeddict_pad.py:118: error: "Movie" has no attribute "clear"
typeddict_pad.py:128: error: Argument 1 to "update" of "TypedDict" has incompatible type "Dict[str, object]"; expected "TypedDict({'name'?: str, 'year'?: int})"
typeddict_pad.py:137: error: Argument 1 to "update" of "TypedDict" has incompatible type "Movie"; expected "TypedDict({'name'?: str, 'year'?: int})"
#!/usr/bin/env python3
"""
https://twitter.com/AlSweigart/status/1170907280285417473
Refactored from https://pastebin.com/raw/hU1m440m by Al Sweigart al@inventwithpython.com
"""
import re
import operator as op
import sys
from typing import NamedTuple, List, Any
@mpkocher
mpkocher / walrus_fstring_example.py
Last active May 9, 2020 21:35
Exploring Py 3.8 Walrus + F-string Tweet By Raymond Hettinger
#!/usr/bin/env python3
"""
Requires Python 3.8
Expanding on a Tweet from RH using walrus and f-strings
https://twitter.com/raymondh/status/1153085050650423296
"""
import logging
@mpkocher
mpkocher / environment.yml
Last active June 26, 2019 17:32
Pyviz Panel. Kicking the Tires
dependencies:
- panel>=0.6.0
- holoviews
- hvplot
- param
- matplotlib
- scipy
- conda-forge::altair
- conda-forge::plotly
- conda-forge::vtk=8.1.1
@mpkocher
mpkocher / DataClasses.ipynb
Created May 25, 2019 01:55
Overview of Dataclasses, namedtuple, typing.NamedTuple, attrs and pydantic
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpkocher
mpkocher / Functional-Python-Part-4.ipynb
Created February 27, 2019 04:34
Functional Programming Techniques in Python: Part 4
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpkocher
mpkocher / Functional-Python-Part-3.ipynb
Last active February 22, 2019 01:05
Functional Python Techniques Part 3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpkocher
mpkocher / Functional-Python-Part-2.ipynb
Last active September 14, 2020 21:43
Functional-Python-Part-2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpkocher
mpkocher / Functional-Python-Part-1.ipynb
Last active February 15, 2019 11:25
Functional Python Part 1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpkocher
mpkocher / AmmoniteOpsExample.ipynb
Created November 7, 2018 00:56
Ammonite Ops /dev/tty: Device not configured Issue
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.