• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Deprecation tools for Python

futurepast

Deprecation tools for Python (and humans). This is rant masquerading as a package.

What are deprecations?

Past me is often sloppy and makes bad decisions. Like giving functions or classes bad names, putting them in the wrong module, or choosing bad default values.

Present me likes to fix this. But if someone else is actually using my code, any change to the user-facing API will break their code, make them unhappy, and in the end maybe even make them stop using my code.

Some API changes can be dealt with in a way that doesn't break user code, though, through deprecations. Here is what I want from a deprecations:

  • If the user is relying on the old API, warn them that this API will be changed / removed in the future, and tell them how to fix it.
  • Allow the user to change the code so they can make use of the new API.
  • Make sure the user never has to worry about this ever again.
  • Drop the old behavior at some point in the future, when all users had a chance to change their code.

The key idea is to allow users to choose when to go from the old API to the new API. The user is bugged with warnings until they take action and change their code. After the user took action, they shouldn't be bugged any more, though. When the old API is finally removed, the user shouldn't need to take any further action.

What does futurepast do?

The futurepast library is meant to make deprecations as pain-free for developers as possible, and help you to make sure no API is broken accidentally.

It provides helpers to

  • rename, move and remove functions, methods, attributes, classes, modules and constants
  • rename and remove parameters
  • change default values of parameters

How does it work?

Let's say we are in version old_version and we want to remove the old API in new_version.

# remove a class
from futurepast import remove

@remove(past=old_version, future=new_version)
class MyClass(object):
    pass


# remove a method

class MyClass(object):
    @remove(past=old_version, future=new_version)
    def my_method(self):
        pass


# renamed a class from OldClass to NewClass
from futurepast import move

@move(old="OldClass", past=old_version, future=new_version)
class NewClass(object):
    pass


# renaming parameter old_parameter to new_parameter

from futurepast import rename_parameter

@rename_parameter(old="old_parameter", new="new_parameter", past=old_version, future=new_version)
def myfunc(new_parameter=default_value):
    pass


# changing default value of parameter

from futurepast import changed_default

@change_default(old=old_default, past=old_version, future=new_version)
def myfunc(parameter=new_default)
    pass

To make it easy for the developer, any deprecation from futurepast will raise an error once future (that is new_version) arrives, so you know when to get rid of the old code.

Once the future arrives, it is enough to simply remove the futurepast decorator.

Assumptions on deprecations

There are some assumptions that are made here for this to work, in particular:

  • Your users update frequently enough (which is the same as you wait long enough between deprecation and removal) that they will at some point use the version with the deprecation warning.
  • Someone looks at the output of the code and sees the warning.
  • They will actually take action.

The first one is the most tricky one, because it's the one you have to worry about. The second and third are somewhat on the users of your code.

So is all good?

Given the requirements on deprecations given above, some things can not be handled nicely. For example changing the return value of a function is not possible in this way, which is something I want to do A LOT. The best work-around might be to rename the function and give the new function the new behavior. There also currently no way to move anything into a different module automatically (because I haven't figured out how).

Patterns to avoid

  • Avoid deprecations at all cost! Even if they are safe, they are still a hassle for the user!
  • Don't break API without letting the user adjust!
  • Don't make the user change the code twice, once on deprecation and once on removal!
  • Make sure the deprecated code can be replaced RIGHT NOW!
  • Don't keep warning the user after they made the change!

More Repositories

1

word_cloud

A little word cloud generator in Python
Python
10,101
star
2

introduction_to_ml_with_python

Notebooks and code for the book "Introduction to Machine Learning with Python"
Jupyter Notebook
7,348
star
3

scipy_2015_sklearn_tutorial

Scikit-Learn tutorial material for Scipy 2015
Python
578
star
4

scipy-2016-sklearn

Scikit-learn tutorial at SciPy2016
Jupyter Notebook
515
star
5

ml-workshop-1-of-4

Introduction to Machine learning with Python, 4h interactive workshop
HTML
303
star
6

COMS4995-s19

COMS W4995 Applied Machine Learning - Spring 19
Jupyter Notebook
303
star
7

scipy-2017-sklearn

Scipy 2017 scikit-learn tutorial by Alex Gramfort and Andreas Mueller
Jupyter Notebook
283
star
8

scipy-2018-sklearn

Scipy 2018 scikit-learn tutorial by Guillaume Lemaitre and Andreas Mueller
Jupyter Notebook
246
star
9

COMS4995-s20

COMS W4995 Applied Machine Learning - Spring 20
Jupyter Notebook
245
star
10

mglearn

mglearn helper package for "Introduction to Machine Learning with Python"
Python
229
star
11

ml-training-intro

Materials for the "Introduction to Machine Learning" class
HTML
227
star
12

ml-training-advanced

Materials for the "Advanced Scikit-learn" class in the afternoon
Jupyter Notebook
163
star
13

ml-workshop-4-of-4

Advanced Machine Learning with Scikit-learn part II
HTML
162
star
14

COMS4995-s18

COMS W4995 Applied Machine Learning - Spring 18
Jupyter Notebook
158
star
15

kaggle_insults

Kaggle Submission for "Detecting Insults in Social Commentary"
Python
153
star
16

ml-workshop-3-of-4

Advanced Machine Learning with Scikit-learn part I
HTML
139
star
17

gco_python

Python wrappers for GCO alpha-expansion and alpha-beta-swaps
Python
131
star
18

ml-workshop-2-of-4

Intermediate Machine Learning with Scikit-learn, 4h interactive workshop
HTML
125
star
19

advanced_training

Advanced Scikit-learn training session
Jupyter Notebook
120
star
20

talks_odt

Slides and materials for most of my talks by year
Jupyter Notebook
89
star
21

applied_ml_spring_2017

Website and material for the FIXME course on Practical Machine Learning
Jupyter Notebook
88
star
22

odscon-2015

Slides and material for open data science
80
star
23

odscon-sf-2015

Material for ODSCON San Francisco 2015
Jupyter Notebook
79
star
24

aml

Applied Machine Learning with Python
Jupyter Notebook
76
star
25

quick-ml-intro

One hour interactive training for ML with scikit-learn
Jupyter Notebook
74
star
26

pydata-nyc-advanced-sklearn

Notebooks (and slides) for my PyData NYC 2014 tutorial on the more advanced features of scikit-learn.
69
star
27

sklearn_tutorial

Slides for quick intro to machine learning with sklearn
CSS
65
star
28

sklearn-one-day

One day workshop for machine learning with scikit-learn
HTML
63
star
29

segmentation

Superpixel based semantic segmentation
Python
53
star
30

scikit-learn-interactive-tutorial

IPython notebooks and data an interactive scikit-learn tutorial.
51
star
31

pydata-strata-2015

Slides and notebooks for PyData Strata San Jose
51
star
32

patsylearn

Patsy Adaptors for Scikit-learn
Python
49
star
33

advanced_git_nyu_2016

Advanced git and github course material
HTML
39
star
34

textonboost

Texton boost implementation in C++ by Philipp Kraehenbuehl
C++
32
star
35

pydata-amsterdam-2016

Machine Learning with Scikit-Learn (material for pydata Amsterdam 2016)
Jupyter Notebook
30
star
36

ml_meetup_nyc_2016

Material for Machine Learning Meetup "Machine Learning with Scikit-learn"
Jupyter Notebook
29
star
37

odsc_east_2016

Jupyter Notebook
26
star
38

speed_reading

Speed reading app with running focus
CSS
25
star
39

slic-python

SLIC wrapper for Python - legacy, rather use scikit-image now!
C++
23
star
40

ml-workshop-short

Two hour interactive machine learning workshop
HTML
22
star
41

mlss_2015

Material for open source machine learning practical
Python
21
star
42

jupytercon2017

Material for Data analysis and machine learning in Jupyter
Jupyter Notebook
21
star
43

structured-prediction-workshop

Introduction to structured prediction with Python and pystruct
TeX
18
star
44

information-theoretic-mst

Information Theoretic Clustering using Minimum Spanning Trees
Python
18
star
45

advanced-sklearn-boston-nlp-2016

Material and slides for Boston NLP meetup May 23rd 2016
Jupyter Notebook
17
star
46

nyu_ml_lectures

Materials for NYU Machine Learning Guest Lectures
Python
17
star
47

amueller.github.io

Less
17
star
48

ImageNet-parsing-Python

Python class to explore the ImageNet database
Python
16
star
49

water_hackweek_2020_machine_learning

Water Hackweek Machine Learning workshop
Jupyter Notebook
15
star
50

strata-nyc-2016

Materials fort Strata NYC 2016 scikit-learn tutorial
Jupyter Notebook
15
star
51

damascene-python-and-matlab-bindings

Python and matlab bindings for the Damascene CUDA implementation of gPB
C++
13
star
52

git_workshop

Material for git workshop
HTML
11
star
53

strata_singapore_2015

Materials for Strata Singapore "Machine learning In Python with scikit-learn" tutorial.
Jupyter Notebook
9
star
54

sklearn_workshop

Jupyter notebooks for interactive scikit-learn workshop
Python
8
star
55

cv

Curriculum Vitae
TeX
7
star
56

datasets

Datasets of some standard computer vision / deep learning benchmarks
Python
7
star
57

GPU-Quickshift-Python-Bindings

Python bindings for Brian Fultersons really quick shift
C++
7
star
58

structured_prediction_talk

Slides for explaining structured prediction and PyStruct
TeX
6
star
59

oss-directions-webinar-2019

Open Source Directions webinar materials
Jupyter Notebook
6
star
60

intro_to_ml_cuny_2015

Introduction to machine learning for CUNY
5
star
61

columbia-website

My official columbia page
CSS
5
star
62

phd-thesis-segmentation

unearthing my thesis - this is a backup
TeX
4
star
63

figures

Some figures and drawings for talks
3
star
64

daimrf

Python interface for inference with LibDAI
Python
2
star
65

notebooks

Random notebooks
2
star
66

vim-config

Vim Script
2
star
67

nsf-biosketch

stand-alone nsf biosketch
TeX
2
star
68

oss_workshop

Demo repository for oss workshop
1
star
69

dask-learn

Python
1
star
70

CZI-sklearn

TeX
1
star
71

gah

Code I don't want to keep reimplementing all the time
1
star
72

dotfiles

Another try to manage my dotfiles
Shell
1
star
73

icra_2014_crf_nyu

ICRA 2014 paper on crfs for semantic segmenation on the nyu dataset
TeX
1
star