←back to thread

517 points bkolobara | 1 comments | | HN request time: 0s | source
Show context
koakuma-chan ◴[] No.45041723[source]
I encourage every one to at least stop writing code in Python.
replies(5): >>45041794 #>>45041941 #>>45042073 #>>45043031 #>>45049992 #
veber-alex ◴[] No.45041941[source]
Here is some actual useful advice:

Use a type checker! Pyright can get you like 80% of Rust's type safety.

replies(7): >>45042031 #>>45042063 #>>45042147 #>>45042269 #>>45043223 #>>45047269 #>>45050186 #
deathanatos ◴[] No.45042269[source]
I've not tried Pyright, but mypy on any realistic, real-world codebase I've thrown at it emits ~80k errors. It's hard to get started with that.

mypy's output is, AFAICT, also non-deterministic, and doesn't support a programmatic format that I know of. This makes it next to impossible to write a wrapper script to diff the errors to, for example, show only errors introduced by the change one is making.

Relying on my devs to manually trawl through 80k lines of errors for ones they might be adding in is a lost cause.

Our codebase also uses SQLAlchemy extensively, which does not play well with typecheckers. (There is an extension to aid in this, but it regrettably SIGSEGVs.)

Also this took me forever to understand:

  from typing import Dict

  JsonValue = str | Dict[str, "JsonValue"]

  def foo() -> JsonValue:
      x: Dict[str, str] = {"a": "b"}
      return x

  x: JsonValue = foo()
That will get you:

  example.py:7: error: Incompatible return value type (got "dict[str, str]", expected "str | dict[str, JsonValue]")  [return-value]
replies(4): >>45042291 #>>45042438 #>>45043507 #>>45043716 #
1. zelphirkalt ◴[] No.45043507{3}[source]
I used mypy just fine for a previous job. If you are getting 80k errors, that means you are either starting very late to use the type checker and have done many dubious things before, or you didn't exclude your venv from being type checked by mypy.