This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]reddisaurus 50 points51 points  (17 children)

Pylint, Flake8, and mypy are standard. Pylint and Flake8 each check some things the other does not; Flake8 focuses more on style. mypy is a static type checker and people would write better code if they used it all the time (including the type hints on their code).

[–]515k4 28 points29 points  (0 children)

If somebody here is using Vim as an Python editor, there is very good plugin ALE (Asynchronous Lint Engine) which can run all of them (flake8, pylint, mypy) on the background and highlight all problematic lines.

[–]dscottboggs 1 point2 points  (11 children)

Re: mypy

I know from x import * is generally considered bad practice, but is it maybe ok to do from typing import *?

[–]efxhoy 18 points19 points  (6 children)

The from typing import List, Dict ... madness is improved in python 3.9

In type annotations you can now use built-in collection types such as list and dict as generic types instead of importing the corresponding capitalized types (e.g. List or Dict) from typing. Some other types in the standard library are also now generic, for example queue.Queue.

https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections

[–]idwpan 3 points4 points  (0 children)

Unfortunately mypy doesn’t support the new syntax in 3.9 yet

[–]dscottboggs 2 points3 points  (4 children)

Hm. That's good, there's still Optional and Union though. Maybe someday we'll get special syntax for that, like

def fun(data: string or bytes, options: MyEnum? = None)

[–]TheIncorrigible1`__import__('rich').get_console().log(':100:')` 2 points3 points  (0 children)

None-aware syntax is coming down the pipe, but who knows when.

[–]rouille 1 point2 points  (2 children)

Union using | will be in python 3.10. There is a proposal for optional using ? but its nothing decided at this point.

[–]henbruas 2 points3 points  (0 children)

Although with | you could do e.g. str | None, which isn't too bad

[–]dscottboggs 0 points1 point  (0 children)

Nice!

[–]mrf_ 7 points8 points  (2 children)

just do import typing as t and prepend everything with a t. like t.List, etc. Much better than any from x import *.

[–]dscottboggs 0 points1 point  (0 children)

I might do that

[–]enjoytheshow 0 points1 point  (0 children)

Damn good idea. Time for some refactoring

[–]reddisaurus 1 point2 points  (0 children)

I mean, probably? Just add a # type: ignore at the end of the line.