Re:Python’s tug of war between beginner-friendly and advance...
by jhardy54 on Thursday February 04, 2021 @08:49PM
(#26032133)
Which linter were you using? ESLint/etc doesn't catch errors like that, you need Typescript (which can work on plain JS files as a linter).
On the other hand, your example is valid Typescript, although if you use attempt `x + 1` then Typescript will yell at you for incompatible types.
Unfortunately your example is also a problem in Python, if not worse:
def foo() -> int:
return 42
# valid
x: int = foo()
# also valid
x: int = foo
Why is this valid?! Well, Python doesn't actually check your type annotations, you have to choose and use a type-checker (example: mypy). There is no default type checker for Python, and invalid types are silently ignored by the interpreter.
On the other hand, your example is valid Typescript, although if you use attempt `x + 1` then Typescript will yell at you for incompatible types.
Unfortunately your example is also a problem in Python, if not worse:
Why is this valid?! Well, Python doesn't actually check your type annotations, you have to choose and use a type-checker (example: mypy). There is no default type checker for Python, and invalid types are silently ignored by the interpreter.