News for hackers. Stuff that matters.
Re:Why if TYPE_CHECKING? by L3viathan on Wednesday December 20, 2023 @06:47AM (#38707594)
> However, Python doesn’t have the compile-time check, because it’s an interpreted language that is dynamically-typed, which means its only real place to check is at runtime

Pet peeve: Python is compiled (into bytecode), so it could theoretically do checks at compile time. The "dynamically-typed" part is correct and is the real reason.

Re:Why if TYPE_CHECKING? by arnsholt on Wednesday December 20, 2023 @08:13AM (#38708244)
The problem for Python with type checking is that the language has essentially no compile-time constructs at all, just a bunch of assignment operators with different syntax: `def` assigns a function object to a variable when it's executed, `import` assigns a module, `class` assigns a class object. This means that everything involving names in Python is just a variable lookup (incidentally, this is why a function call must follow the declaration in Python: the variable is unbound if you haven't executed the function definition yet). The reason `Sequence` fails in the example in the article is simply that the code is trying to read an unassigned variable, no different from writing `vairable` instead of `variable` in your code.
Re:Why if TYPE_CHECKING? by remram on Wednesday December 20, 2023 @06:59AM (#38707671)
TypeScript is also interpreted, and does type checking without running code. Their argument is very weird.
Re:Why if TYPE_CHECKING? by kaoD on Wednesday December 20, 2023 @07:58AM (#38708113)
TS is not interpreted. It compiles to JS, which is interpreted, but TS itself is not. There are no TS interpreters, they all compile to JS behind the scenes.

Or does Deno run TS natively? At a glance it looks like even its runtime is written in JS[0].

EDIT: looks like they have bindings for V8[1] so yeah, just a JS interpreter behind the scenes.

[0] https://github.com/denoland/deno/tree/main/runtime/js

[1] https://github.com/denoland/rusty_v8

Re:Why if TYPE_CHECKING? by SlimTim10 on Wednesday December 20, 2023 @07:23AM (#38707837)
That's an odd thing to say. The distinction between compiled and interpreted languages is very fuzzy, but TypeScript is clearly on the compiled side.
Re:Why if TYPE_CHECKING? by gpderetta on Wednesday December 20, 2023 @09:33AM (#38709085)
It is not so much that it is fuzzy, it is that the two definitions are not exclusive.

A compilation translates a language to another, whether it is native code, internal bytecode, portable bytecode, or another source language. Compilation might also type check and optimize depending on the language. Interpretation executes a language; normally bytecode is executed, but pure source level interpreters exist. Native code is "interpreted" by the cpu itself of course.

For example JAVA is certainly a compiled language, but it is typically compiled to bytecode and then interpreted or JITed (which is a combined interpreter/compiler).

Re:Why if TYPE_CHECKING? by remram on Wednesday December 20, 2023 @12:56PM (#38711509)
Likewise, the Python typing annotation language could very well be on the compiled side...

Someone took the interpreted JavaScript language, added typing syntax on top, and typing can be checked statically.

The Python team took the interpreted Python language, added typing syntax on top, and here we are reading a claim that it can't be checked statically because it's interpreted. You understand my puzzlement.