Using typing.Generic in Python

Posted on Fri, 18 Feb 2022 in Python • Tagged with python, type hints, typing, mypy, PyCharm

I am working on a project with a relatively large code-base. And it has a history. Our team wrote some parts of it way before type-hints. And we steel add hints to the legacy code or improve them. Is it worth the fuss? Sure! Our users are developers. They open our code in PyCharm every day. And they hope that it will help them to solve their task as quickly as possible.


Continue reading

What are good Python interview questions?

Posted on Fri, 14 May 2021 in Python • Tagged with python, programming, interview

There are no good Python interview questions. Why? Because you want to hire a good developer, not a Python nerd. I used to think that there are some good Python-related problems to solve during the interview. But I doubt there is any.

I've interviewed more than 30 developers. I've gradually drifted from only-python-nerd-knows-the-answer questions to general programming problems to solve. There are several reasons for that.


Continue reading

Type Hints for Dynamic Class Creation

Posted on Sun, 15 Mar 2020 in Python • Tagged with python, type hinting

Type hints in Python are cool. Projects of any size can benefit from them. Actually for projects bigger than 50-60 modules or with more than 5 developers involved type hints become crucial to keep its code quality at a reasonable level. And it looks like it is my favorite topic to write about.

But sometimes, its realization in Python is counterintuitive or even confusing. You have to write a code that has no sense but typing, for example, in case of dynamic type creation and necessity of using cast function. Well, technically all type hints in Python have no sense but typing. However, in the vast majority of cases, type annotation adds clarity to the code, not confusion.


Continue reading

What is Python not good for?

Posted on Tue, 15 Oct 2019 in Python • Tagged with python

There is a question on Quora - "What is Python not good for?" I want to say that Python is good for everything, but it is not true. Honestly, Python is a second-best language for many things. There are not many spots there it is the best language to use.


Continue reading

Python Typing Hints List

Posted on Fri, 24 May 2019 in Python • Tagged with python, type hints

Here is my small list of sources of type hints in Python that I use almost every day.


Continue reading

Using import foo.bar.baz as fbb

Posted on Mon, 18 Mar 2019 in Python • Tagged with python

There is a wonderful feature in Python import statement to make an alias for an imported object (import foo.bar.baz as fbb). It allows to avoid name conflicts and improve code readability if necessary. And of course, using it you can easily turn your perfect code into a completely unreadable mess. Recently I’ve seen this several times. I’ve met some strange abbreviations and confusing aliases.


Continue reading

Please Do Not Use "else"

Posted on Tue, 29 Jan 2019 in Python • Tagged with python

I don’t like else if there is return-statement in both branches. It is always possible to write code without that unnecessary if appendage. Such code looks more accurate, more clear and it is easier to read. Why so many developers still use this useless else?


Continue reading

Mobile App with Kivy and Python? Mmm… Not now

Posted on Thu, 25 Oct 2018 in Python • Tagged with python, kivy, mobile

There are several GUI frameworks for Python. Most of them are for desktop applications. Kivy is an exception. Using it you can build project for mobile platforms. Unfortunately, it is not production ready. You have to juggle versions of libraries to make it works. So even having a t-shirt that says print("Python is my favorite language") I have to accept that Python is not for mobile development.


Continue reading

Optional or Not in Abstract Classes

Posted on Mon, 27 Aug 2018 in Python • Tagged with python, type hints

Type hints are not mandatory in Python. So you can use them or not. If you decide work with them you’ll face many difficulties annotating functions or variables. This article shows my point of view on one specific case.


Continue reading

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