Skip to content

Instantly share code, notes, and snippets.

View ncoghlan's full-sized avatar

Alyssa Coghlan ncoghlan

View GitHub Profile
@ncoghlan
ncoghlan / it-reference.md
Last active February 16, 2018 02:10
PEP 505 alternative: the "?it" symbolic reference

Using ?it as a statement local symbolic reference

Core concept

  • (?it=expr) is a new atomic expression for an "it reference binding"
  • subsequent subexpressions (in execution order) can reference the bound subexpression using ?it (an "it reference")
  • ?it is reset between statements, including before entering the suite within a compound statement (if you want a persistent binding, use a named variable)
@ncoghlan
ncoghlan / interactive-example.txt
Created July 24, 2018 15:28
API renames, aliasing, and cross-version pickle compatibility
>>> class C:
... def example(self): pass
...
>>> import pickle
>>> data = pickle.dumps(C.example)
>>> pickle.loads(C.example)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'function'
>>> pickle.loads(data)