Skip to content

Instantly share code, notes, and snippets.

View 1st1's full-sized avatar

Yury Selivanov 1st1

View GitHub Profile
@1st1
1st1 / gist:2029032
Created March 13, 2012 14:12
Alternate PEP 362 Implementation
##
# Copyright (c) 2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##
import inspect
import collections
@1st1
1st1 / gist:2871349
Created June 4, 2012 22:58
pep 362 example
def render_signature(signature):
'''Renders function definition by its signature.
Example:
>>> def test(a:'foo', *, b:'bar', c=True, **kwargs:None) -> 'spam':
... pass
>>> render_signature(inspect.signature(test))
test(a:'foo', *, b:'bar', c=True, **kwargs:None) -> 'spam'
@1st1
1st1 / shell.py
Last active December 17, 2015 06:59
An extension for python REPL, inspired by PostgreSQL shell. Write '\e' to open an external editor for commands, '\r' to reset the buffer.
##
# Copyright 2013 Yury Selivanov <yselivanov@sprymix.com>
# License: MIT
##
import code
import subprocess
import os
import sys
import asyncio
import time
I = 0
def test2():
yield from ()
global I
I += 1
log_level = logger.getEffectiveLevel()
if log_level <= INFO:
t0 = self.time()
event_list = self._selector.select(timeout)
t1 = self.time()
argstr = '' if timeout is None else ' {:.3f}'.format(timeout)
if t1-t0 >= 1:
level = logging.INFO
logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
elif log_level <= DEBUG:
======================================================================
FAIL: test_builtins (idlelib.idle_test.test_calltips.Get_signatureTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/yury/dev/py/cpython/Lib/idlelib/idle_test/test_calltips.py", line 59, in test_builtins
'x.__init__(...) initializes x; see help(type(x)) for signature')
File "/Users/yury/dev/py/cpython/Lib/idlelib/idle_test/test_calltips.py", line 53, in gtest
self.assertEqual(signature(obj), out)
AssertionError: 'Initializes self. See help(type(self)) for accurate signature.' != 'x.__init__(...) initializes x; see help(type(x)) for signature'
- Initializes self. See help(type(self)) for accurate signature.
import inspect
def inherit(*, base, docs=False, signature=False):
assert docs or signature
assert isinstance(base, type) # we can also support functions
def wrap(func):
base_func = getattr(base, func.__name__)
> --- a/Lib/inspect.py Thu Feb 06 22:06:16 2014 -0500
> +++ b/Lib/inspect.py Fri Feb 07 13:41:22 2014 -0500
< +def _strip_non_python_syntax(signature):
---
> +def _signature_strip_non_python_syntax(signature):
> + # Internal helper to convert AC extended signature format
> + # to the standard Python syntax
> +
99a103,106
> - if first_parameter_is_self:
class Local:
def __getattr__(self, attr):
# finds 'attr' stored for the current Task.context_id
def __setattr__(self, attr, val):
# stores value for the current Task.context_id
local = Local()
import asyncio
import time
import statistics
import heapq
ITERS = 2000
NUMBER_OF_TASKS = 100000
loop = asyncio.get_event_loop()