3 useful Python tools to make your code easier



Any developer uses one or another auxiliary tool. Some of them allow you to speed up the process, some - get rid of errors, make the code more understandable. There are such tools in almost every area of โ€‹โ€‹development.



Preston Badeer, a Python programmer, shared a set of extensions that, in his opinion, greatly simplify and speed up coding. For 5 years of work, he tried many tools and identified three of the most useful.



Kite: quick access to documentation and AI-powered autocomplete



Most IDEs have built-in auto-complete functionality. The process of working with them looks like this.





These tools use internal documentation to automatically substitute parameters and function names. But what if there was a tool that could help not only with function names, but also with frequently used pieces of code? He also analyzed the data of the GitHub repositories and offered the necessary hints. There is such a tool. Kite does a lot, but most of the important features can be divided into three groups.



AI-powered smart tips



Kite learns the codebase, remembers the names of variables that developers often use, parameter names from the Internet, and documentation to provide contextual recommendations, for example:





The example shows how Kite predicts which variables you will use depending on the context of your code. Here's another example of how hints work:





โ€œWe spent a lot of time semantically indexing all the code on GitHub, building statistical inferences and extensive models that help us use the information,โ€ comments Adam Smith, CEO of Kite.



Improved documentation handling



If your colleagues have never sent you "RTFM" in the work chat, then you are a developer who does not make mistakes. But, in any case, you should first read the documentation, and then ask colleagues about a problem or look for answers to questions on Stack Overflow. Reading the documentation is an important step in creating program code. It will be made more convenient by Kite Copilot, which shows in real time a description of objects and functions highlighted by the cursor.





Your code remains with you on your local PC



Kite is built for local use and does not push code to the cloud. The speed of the prompts is quite high. This is important for those who have slow internet or work related to closed / proprietary code.



I have been working with this tool for several years and it only gets better. You can try it right now .



Improving the code with Mypy



Python is a dynamically typed language that allows you to make any variable with any data type at any time. The same variable can be either a string, or an integer, or another data type, depending on the last value assigned. This speeds up the coding process when the developer does not have to manually assign the data type to the variables each time.



# These two variable types are declared the exact same way
# Python figures out the data type on it's own, dynamically

# string
var_name = "string here"

# integer
var_name = 1234


And here is an example of a statically typed language, where each variable is assigned a specific data type, which must be adhered to in logic:



# Many languages require the data type to be declared too

# string
str var_name = "string here"

# integer
int var_name = 1234


There are also disadvantages to the dynamic approach:



  • By the end of the development process, the risk of encountering errors increases, so you will have to rewrite some parts of the code.
  • Because of the constant computation of types, the code runs slower.
  • Because of dynamic typing, the code becomes unsafe, since the input and output of the function can have different data types for the same variable.
  • Dynamic code is more difficult to read because another developer cannot be 100% sure that a previously declared variable will not change its type.


The free Mypy tool injects static typing into your code. It allows you to find type mismatch errors in your code. If the value of a variable does not match the assigned type, an error is output.



# Declaring a function using normal dynamic typing, without mypy
def iter_primes():
   # code here#

 Declaring the same function with mypy static typing
from typing import Iterator

def iter_primes() -> Iterator[int]:
   # code here


This is the simplest example in the entire list. If you need more information, follow the link . Also, there is an extensive FAQ in the Mypy documentation .



Find bugs quickly and write simple functions with SonarLint



Most IDEs have linters, static error analyzers. Linter can find an error even before running the code. This is considered statistical analysis of the code.





But there is also dynamic analysis, which runs / compiles the code in the background, checking that it works correctly. And if something goes wrong, it reports a possible error. This is exactly how the free project SonarLint works .



Commented out or unused code



I confess that I leave statements, commented out code, and unused functions throughout the codebase. SonarLint warns of these problems by showing you where everything is. Without SonarLint, troubleshooting and debugging can take hours.







Security



Issues SonarLint has a large, updatable vulnerability database that allows the plugin to promptly warn the developer about problems found in the code.



Code readability



SonarLint warns of over-complicating the code by explaining the problem. It can be, for example, too much nesting of if statements.



As a conclusion



A small summary, so as not to forget the tools described in the article:





What useful Python tools do you use?






All Articles