4 Articles about Python Internals

Posted on Thu, 29 Mar 2018 in Python • Tagged with python, python internals, cpython

Maybe, knowing Python internals is not a thing you should know to be a good Python developer. However, if you want to improve your code it becomes more important. If you know it works under the hood, you write a code with less stupid mistakes and architecture issues.


Continue reading

Tuple[Callable, Any, ...]

Posted on Mon, 29 Jan 2018 in Python • Tagged with typing, mypy, python

Type hints could help you a lot with a big Python project. However, they sometimes require code refactoring. I wrote about it last year in this article, but I have found a good example for this only now.


Continue reading

How to add type hints into Python 2.7 project

Posted on Mon, 11 Dec 2017 in Python • Tagged with typing, mypy, python

Many times I wrote that type hints in Python help to work with big or moderate projects. However, if you decide to add them to your project, you have to check your project regularly using CI. And this kind of checks is not easy to implement. This article is my story about obstacles in this process.

I'm trying to add type hints to our project for a while. And now I have a bunch of methods how to do it more efficiently, fast, and painless. I spend many days trying to find them. Now I want to share my experience.


Continue reading

9 Useful Articles about Asyncio

Posted on Fri, 20 Oct 2017 in Python • Tagged with python

asyncio is a useful library. However, it is not so easy to understand how to work with it. Documentation isn't enough. We need more examples. We need more explanations. The last couple of weekends I spent experimenting with this library. After that, I add some interesting articles into my Pocket. Here are some of them.


Continue reading

Python project integrity requires extra efforts

Posted on Fri, 06 Oct 2017 in Python • Tagged with python

Python is a very flexible programming language. Its dynamic nature allows programmers to code elegant solutions that almost impossible to make with other more strict languages, for example, Java. However, you have to pay for everything. While Python code base grows, it requires more and more efforts to keep project integrity. Without these extra efforts, the project will fall apart.


Continue reading

Hash function for function in Python

Posted on Mon, 11 Sep 2017 in Python • Tagged with python, cpython

A couple of weeks ago one of my colleagues ask if Python function is possible to use as a key in dicts? Yes, it is. So, every function has a hash. But how is it calculated? Based on function name? Based on function byte code? Actually, it calculates by transforming a pointer to a function object. However, it is not so easy to find it in the CPython code.


Continue reading

Property in Child Class

Posted on Tue, 30 May 2017 in Python • Tagged with python, property

It looks obvious that you can override the property in a child class, and call "super" within it. Sounds OK? Yes, it is. However, when my colleague asked me about this behavior, I was confused. Maybe because I am a bit suspicious, every time I saw a magic thing of any kind in a code I expect a trap. What's why I decided to write a simple example to prove myself that it works as it should.


Continue reading

Pyenv on Mac

Posted on Fri, 19 May 2017 in Python • Tagged with python, pyenv

It can be painful to manage several Python versions on one laptop. However, it is a very common situation. Usually, developers have many projects that require different Python versions. There are a couple of variants to deal with it. My favourite is pyenv with virtualenv plugin. I used to use Homebrew itself to do that, but it wasn't so flexible.


Continue reading

Enums in Python

Posted on Fri, 17 Feb 2017 in Python • Tagged with enums, python

Enums are less used feature in Python. We as programmers prefer to use weird dicts or lists where enum should be used. Why? Because it is rather new feature and you have to install back port library if you use Python 2.7. However, it's better to use them in many cases.


Continue reading

Java-like Optional in Python

Posted on Wed, 23 Nov 2016 in Python • Tagged with python, java

Sometimes using None makes a mess of a code. For example, if you want to separate some "empty" value and "no data" value for integer input where 0 isn't "empty" value, it's very hard to do with None only. Possible solution is to use something like Optional in Java.


Continue reading