Articles tagged python

  1. py.test sprint in Freiburg

    By Floris Bruynooghe

    Testing is a really important part of Python development and picking the testing tool of choice is no light decision. Quite a few years ago I eventually decided py.test would be the best tool for this, a choice I have never regretted but has rather been re-enforced ever since …

  2. Pylint and dynamically populated packages

    By Floris Bruynooghe

    Python links the module namespace directly to the layout of the source locations on the filesystem. And this is mostly fine, certainly for applications. For libraries sometimes one might want to control the toplevel namespace or API more tightly. This also is mostly fine as one can just use private …

  3. New pytest-timeout release

    By Floris Bruynooghe

    At long last I have updated my pytest-timeout plugin. pytest-timeout is a plugin to py.test which will interrupt tests which are taking longer then a set time and dump the stack traces of all threads. This was initially developed in order to debug some some tests which would occasionally …

  4. Designing binary/text APIs in a polygot py2/py3 world

    By Floris Bruynooghe

    The general advice for handling text in an application is to use a so called unicode sandwich: that is decode bytes to unicode (text) as soon as receiving it, have everything internally handle unicode and then right at the boundary encode it back to bytes. Typically the boundaries where the …

  5. Don't be scared of copyright

    It appears there is some arguments against putting copyright statements on the top of a file in free software or open source projects. Over at opensource.com Rich Bowen argues that it is counter productive and not in the community spirit (in this case talking about OpenStack). It seems to …

  6. Small Emacs tweaks impoving my Python coding

    By Floris Bruynooghe

    Today I've spent a few minutes tweaking Emacs a little. The result is very simple yet makes a decent impact on usage.

    Firstly I remembered using the c-subword-mode a long time ago, I couldn't believe I never used that in Python. Turns out there is a more genericly named subword-mode …

  7. Using __getattr__ and property

    By Floris Bruynooghe

    Today I wasted a lot of time trying to figure out why a class using both a __getattr__ and a property mysteriously failed. The short version is: Make sure you don't raise an AttributeError in the property.fget()

    The start point of this horrible voyage was a class which looked …

  8. Synchronising eventlets and threads

    By Floris Bruynooghe

    Eventlet is an asynchronous network I/O framework which combines an event loop with greenlet based coroutines to provide a familiar blocking-like API to the developer. One of the reasons I like eventlet a lot is that the technology it builds on allows it's event loop to run inside a …

  9. Creating subprocesses in new contracts on Solaris 10

    Solaris 10 introduced "contracts" for processes. You can read all about it in the contract(4) manpage but simply put it's a grouping of processes under another ID, and you can "monitor" these groups, e.g. be notified when a process in a group coredumps etc. This is actually one …

  10. Return inside with statement

    By Floris Bruynooghe

    Somehow my brain seems to think there's a reason not to return inside a with statement, so rather then doing this:

    def foo():
        with ctx_manager:
            return bar()
    

    I always do:

    def foo():
        with ctx_manager:
             result = bar()
        return result
    

    No idea why nor where I think to have heard/read this …

  11. Templating engine in python stdlib?

    By Floris Bruynooghe

    I am a great proponent of the python standard library, I love having lots of tools in there and hate having to resort to thirdparty libs. This is why I was wondering if there could be a real templating engine in the stdlib some day? I'm not a great user …

  12. Europython, threading and virtualenv

    By Floris Bruynooghe

    I use threads

    correctly

    I do not use virtualenv

    and dont't want to

    Just needed to get that out of my system after europython, now mock me.

    PS: I should probably have done this as a lightening talk but that occurred to me too late.

  13. weakref and circular references: should I really care?

    By Floris Bruynooghe

    While Python has a garbage collector pretty much whenever circular references are touched upon it is advised to use weak references or otherwise break the cycle. But should we really care? I'd like not to, it seem like something the platfrom (python vm) should just provide for me. Are all …

  14. python-prctl

    By Floris Bruynooghe

    There is sometimes a need to set the process name from within python, this would allow you to use something like pkill myapp rather then the process name of your application just being yet another "python". Bugs (which I'm now failing to find in Python's tracker) have been filed about …

  15. Storm and sqlite locking

    By Floris Bruynooghe

    The Storm ORM struggles with sqlite3's <http://docs.python.org/library/sqlite3.html> transaction behaviour as they explain in their source code. Looking at the implementation of .raw_execute() the side effect of their solution to this is that they start an explicit transaction on every statement that gets executed. Including …

  16. Python optimisation has surprising side effects

    By Floris Bruynooghe

    Here's something that surprised me:

    a = None
    def f():
        b = a
        return b
    def g():
        b = a
        a = 'foo'
        return b
    

    While f() is perfectly fine, g() raises an UnboundLocalError. This is because Python optimises access to local variables using the LOAD_FAST/STORE_FAST opcode, you can easily see why this …

  17. Judging performance of python code

    By Floris Bruynooghe

    Recently I"ve been messing around with python bytecode, as a result I now know approximately how the python virtual virtual machine works at a bytecode level. I've found this quite interesting but other then satisfying my own curiosity had no benefit from this knowledge. Until today I was wondering …

  18. Hacking mock: Mock.assert_api(...)

    By Floris Bruynooghe

    Mock is a great module to use in testing, I use it pretty much all the time. But one thing I have nerver felt great about is the syntax of it's call_args (and call_args_list): it is a 2-tuple of the positional arguments and the keyword arguments, e.g. (('arg1', 'arg2' …

  19. Using lib2to3 in setup.py

    By Floris Bruynooghe

    It seems that many people think you need distribute if you want to run 2to3 automatically in your setup.py. But personally I don't like setuptools (aka distribute) and hence don't like forcing this on users. No worries since plain old distutils supports this as well, but it simply appears …

  20. Discovering basestring

    By Floris Bruynooghe

    This may seem simple and trivial, but today I discovered the basestring type in Python. It is essentially a base type for str and unicode, which comes in handy when writing isinstance(foo, basestring) in test code for example.

    Strangely, despide PEP 237 mentioning the equivalent for int and long …

  21. Terminology

    By Floris Bruynooghe

    Why was it ever considered desirable to call a directory containing a __init__.py file a "package" rather then just "module". They are after all simply "modules containing other modules". It's not like that solved some sort of problem was it? But, as sad as that sometimes might be, we …

  22. Decorators specific to a class

    By Floris Bruynooghe

    My gut tells me it's horribly wrong but I am failing to formulate a decent argument, let me show an example what I mean (somewhat contrived):

    def deco(f):
        def wrapper(self, *args, **kw):
            with self.lock:
                f(self, *args, **kw)
    
    class Foo:
        def __init__(self):
            self.lock = threading.Lock …
  23. Setting descriptors on modules

    By Floris Bruynooghe

    This counts for one of the more crazy things I'd like to do with Python: insert an instance of a descriptor object into the class dict of a module.

    While you can get hold of the module type class by using the __class__ attribute of any module or use types …

  24. Skipping slow test by default in py.test

    By Floris Bruynooghe

    If you got a test suite that runs some very slow tests it might be troublesome to run those all the time. There is of course the "-k" option to py.test which allows you to selectively enable only a few tests. But what I really wanted was a way …

Page 1 / 4 »