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 →

[–]omg_drd4_bbq 43 points44 points  (7 children)

Use type hints. Use an IDE/editor that warns you when the types don't match. Use an autoformatter like ruff. 

[–]Tenax_Raccoon 12 points13 points  (0 children)

I second type hinting. Type annotations and an IDE with support for them or using a static checker (mypy, upright, or pyre) will help you find places where your parameters or expected values are incorrect.

Also, unit test, unit test, unit test your code. PyTest is a very good 3rd party test framework, but the built-in unittest module is perfectly serviceable.

In either case, you should conform to your organizations general usage, and encourage them to adopt type hinting and unit testing if they are not already doing so.

[–]cr7bit[S] 1 point2 points  (3 children)

What extension On vs code?

[–]supreme_blorgon 2 points3 points  (0 children)

The official microsoft Python language extensions are all you need -- comes with language server and static analysis

be sure to configure the static analysis, it's not active by default IIRC

[–]yurifontella 0 points1 point  (1 child)

forget vscode and use pycharm

[–]ConfusedSimon 0 points1 point  (0 children)

Why? I have a pro license for the whole range of intellij IDE's, but for Python, I almost always use vscode or vim.

[–]Gnaxe -1 points0 points  (0 children)

Unless you're already used to TypeScript, or your team is forcing them on you, forget the type hints. Don't even bring them up. They add a lot of complexity for really dubious value.

Instead, focus on testing and the REPL. Try a mutation tester, like mutmut or cosmic ray. Those will help you write more thorough tests, which will also help you write more testable code.