hongminhee

- friends
2,955 link karma
527 comment karma
send messageredditor for
what's this?

TROPHY CASE


  • Three-Year Club

    Verified Email

Common Korean slang/swear words? by Hollololowayin Korean

[–]hongminhee 0 points1 point ago

My friends say 쩐다/쩌네/쩔어. Although I cannot exactly explain its meaning and nuance, it seems similar to so bad.

TypeQuery: A simple and dirty way to define generic methods to existing types by hongminheein Python

[–]hongminhee[S] 0 points1 point ago

Frankly I had not known simplegeneric. It seems to share equivalent features and the same limitations as well except I will fix one of the limitations:

  • The first argument is always used for dispatching, and it must always be passed positionally when the function is called.

TypeQuery 2.0 will provide multiple dispatch as well. You would be able to easily make generic multimethods as CLOS or Clojure can do.

One of trivial differences is Python compatibility: simplegeneric supports Python 2.4+ while TypeQuery supports Python 2.5+. Instead simplegeneric does not mention about Jython or PyPy but TypeQuery makes the guarantee these alternative implementations as well.

TypeQuery: A simple and dirty way to define generic methods to existing types by hongminheein Python

[–]hongminhee[S] 1 point2 points ago

Behind story: I used to want to add polymorphic methods to existing types including built-in types, classes defined by others and classes that are not natural to contain these methods. Initially I had written methods like:

def typequerying_method(value):
    if isinstance(value, basestring):
        return something
    elif isinstance(value, thirdparty.Something):
        return something
    elif isinstance(value, Something):
        return something
    raise TypeError()

Of course that was horrible and especially hard to add types. I had begun to maintain a dict of types to functions, and such methods showed me a pattern.

It was written to avoid copy-and-paste a single file named visitor.py from my old projects to my new projects every time. Thanks!

The Python Method Resolution Order by gthankin Python

[–]hongminhee 1 point2 points ago

Multiple inheritance is not so bad.

The Python Method Resolution Order by gthankin Python

[–]hongminhee 0 points1 point ago

FYI, C3 linearization, used by Python for MRO, was initially introduced by/for Dylan language. I remember that Dylan was one of the most modern languages in the world. :-)

cocoa-python: Port of Objective-C runtime to Python using ctypes by VilleHopfieldin Python

[–]hongminhee 0 points1 point ago

Probably because you can use this in various interpreters including PyPy?

Jython 2.7 is in development by takluyverin Python

[–]hongminhee 1 point2 points ago

It is the news I have been looking for! I will add jython env into my tox.ini configurations. :-)

Armin Rigo experiments FFI for Python by hongminheein Python

[–]hongminhee[S] 0 points1 point ago

What FFIs mainly do is calling functions written in another language (C in most cases). There are ctypes for Python, JNI for Java, P/Invoke for C#, extern in "C" for C++, etc.

As I guess the FFI library I linked above is trying to implicitly match signatures built on top of ctypes. ctypes currently requires to specify signatures of function to call. These could become innecessary if it can parse headers (.h files) and transform them into ctypes signatures.

Armin Rigo experiments FFI for Python by hongminheein Python

[–]hongminhee[S] 0 points1 point ago

These are not FFI libraries but parsers.

Armin Rigo experiments FFI for Python by hongminheein Python

[–]hongminhee[S] 1 point2 points ago

Yes. It seems similar to ctypes but higher than that.

GRequests allows you to use Requests with Gevent to make asyncronous HTTP Requests easily by kracekumarin Python

[–]hongminhee 6 points7 points ago

You probably already know about nonblocking I/O. Recently widely used nonblocking I/O libraries like node.js use callbacks to interop with event loops (we exactly call it continuation-passing style).

The philosophy of gevent (and eventlet) is that nonblockong codes have to be seem alike ordinary blocking codes though these actually block nothing. To achieve that gevent provides monkey patcher (gevent.monkey) which replaces all built-in networking libraries of Python (e.g. socket, urllib2) with nonblocking version provided by gevent.

As a result most of blocking-looking codes become nonblocking by monkey patcher:

from gevent.monkey import patch_all; patch_all()
import urllib2
import json


def get_followers(screen_name):
    url = 'http://api.twitter.com/1/followers/ids.json' \
          '?screen_name={0}&cursor={1}'
    next_cursor = -1
    ids = []
    while next_cursor:
        u = urllib2.urlopen(url.format(screen_name, next_cursor))
        data = json.load(u)
        for id_ in data['ids']:
            yield id_
        next_cursor = data['next_cursor']


print list(get_followers(screen_name='lily199iu'))

The above code is equivalent to the following node.js code which is harder to read:

var http = require('http');

function getFollowers(screenName, complete, cursor) {
  var path = '/1/followers/ids.json?screen_name=' + screenName
           + '&cursor=' + (cursor || '-1');
  http.get({ host: 'api.twitter.com', path: path }, function (res) {
    res.setEncoding('utf8');
    var buffer = '';
    res.on('data', function (chunk) {
      buffer += chunk;
    })
    res.on('end', function () {
      var data = JSON.parse(buffer);
      if (data['next_cursor']) {
        getFollowers(screenName, function (d) {
          complete(data['ids'] + d);
        }, data['next_cursor_str']);
      } else {
        complete(data['ids']);
      }
    });
  });
}

getFollowers('lily199iu', function (data) {
  console.log(data);
});

(Point: iteration v. recursion)

The Python yield keyword explained by jackhammer2022in Python

[–]hongminhee 0 points1 point ago

Precisely that is a generation expression, not a generator. The yield syntax used for functions that create a new generator instance.

PyPy STM design notes by hongminheein Python

[–]hongminhee[S] 3 points4 points ago

My summary: In most cases transactions seem serialized but actually works in parallel. If you do I/O in a transaction block it will actually works in serial and others block/restart.

I think this is not incidental because PyPy transactions have to be transparent, which means it always seem to work in serial even if it works actually in parallel. In other words, because pypy-stm should be a drop-in replacement of pypy/python as well as it actually executes transactions without GIL.

As the note itself said it is somewhat subtle.

how can pip be improved? by myusuf3in Python

[–]hongminhee 0 points1 point ago

You know it is not a problem of pip, but PyPI. In theory pip can play with any repositories that support cheeseshop protocol.

how can pip be improved? by myusuf3in Python

[–]hongminhee 7 points8 points ago

What I have really wanted for pip is parallel installation. Currently pip tries to install whole dependency graph in serial.

Flask -> Werkzeug
      -> Jinja2
Flask-Mail -> Flask
           -> blinker
           -> Lamson -> chardet
                     -> Jinja2
                     -> mock
                     -> nose
                     -> python-daemon

The above graph can be naively resolved in three parallel steps (and can be improved more if it gets right):

  • Flask, Flask-Mail
  • Werkzeug, Jinja2, blinker, Lamson
  • chardet, mock, nose, python-daemon

Gevent tutorial by eduardogottiin Python

[–]hongminhee 1 point2 points ago

In recent versions gevent.wsgi has been deprecated and replaced by gevent.pywsgi. The former one uses HTTP implementations of libevent and the latter is written in pure Python. gevent is moving to libev from libevent, so gevent.wsgi is not more available. :-) Moreover HTTP implementation of libevent has several bugs.

view more: next