This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
def example1(): | |
try: | |
pass # nothing is raised | |
except Exception as e1: | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def func(): | |
try: | |
raise ValueError('ve') | |
except Exception as e: | |
handle_exception(e) | |
def handle_exception(e): | |
if 'some terrible thing' in e.args[0]: | |
raise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import ExitStack | |
d = {index: str(index) for index in range(100)} | |
with ExitStack() as stack: | |
for key in d: | |
if key % 13 == 0: | |
stack.callback(d.pop, key) | |
print(d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache | |
import threading | |
import time | |
def per_instance(factory, *factory_args, **factory_kwargs): | |
"""Applies the given decorator on a per-instance basis.""" | |
def lazy_binder(method): | |
"""Replaces the method just in time when it is first invoked.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import time | |
loop = asyncio.get_event_loop() | |
async def go(sleep): | |
await asyncio.sleep(sleep) | |
print('I slept', sleep, 'seconds') | |
def clog(sleep): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import sys | |
import signal | |
def ensure_dead_with_parent(): | |
"""A last resort measure to make sure this process dies with its parent. | |
Defensive programming for unhandled errors. | |
""" | |
if not sys.platform.startswith('linux'): | |
return # not supported on OS X, Windows, etc. Use process groups. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Create the environment | |
rm -rf .v # remove old stuff if present | |
python3 -m venv .v | |
source .v/bin/activate | |
cd .v | |
pip install flake8==3.2.1 | |
pip install flake8-bugbear==16.12.1 # the newer version works around the issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'.gfm.source': | |
'editor': | |
'softWrap': true | |
'tabLength': 4 | |
'preferredLineLength': 72 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Lib/tokenize.py 2018-04-22 17:33:48.000000000 -0700 | |
+++ Lib/lib2to3/pgen2/tokenize.py 2018-04-22 17:32:55.000000000 -0700 | |
@@ -31,14 +31,15 @@ | |
import itertools as _itertools | |
import re | |
import sys | |
-from token import * | |
+from .token import * | |
cookie_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class PythonFormatLinter extends ArcanistFutureLinter { | |
public function getLinterName() { | |
return 'BLACK'; | |
} | |
protected function getFuturesLimit() { | |
return 8; | |
} |