Live data from Hacker News

Why if TYPE_CHECKING?

vickiboykis.com

71–74 of 74 posts

Re: Why if TYPE_CHECKING?

#71
post #56

Earlier quoted context omitted.

It is not. As the function `print("hi")` is executed, the argument type in this case becomes `Any`, as it would be for any other executed function. As stated in the typing documentation [0]: "the only legal parameters for type are classes, Any, type variables, and unions of any of these types". [0] https://docs.python.org/3/library/typing.html

That's fine and all. But it runs without errors or warnings. I can put that in main.py and do `python3 main.py` and it will simply run fine. What is the point of this whole system if it's not enforced?

Amen.

Re: Why if TYPE_CHECKING?

#72
post #56

Earlier quoted context omitted.

It is not. As the function `print("hi")` is executed, the argument type in this case becomes `Any`, as it would be for any other executed function. As stated in the typing documentation [0]: "the only legal parameters for type are classes, Any, type variables, and unions of any of these types". [0] https://docs.python.org/3/library/typing.html

That's fine and all. But it runs without errors or warnings. I can put that in main.py and do `python3 main.py` and it will simply run fine. What is the point of this whole system if it's not enforced?

If you want type checking, run mypy.

If you don't want type checking, don't run mypy.

I don't see what's so difficult. If it was technically possible to run programs that have type errors in other languages, they would have the option to ignore type errors too, because it's convenient.

Typescript also ignores errors (generating js output for you to run) by default, so what's the point if it's not enforced?

Re: Why if TYPE_CHECKING?

#73
post #72

Earlier quoted context omitted.

That's fine and all. But it runs without errors or warnings. I can put that in main.py and do `python3 main.py` and it will simply run fine. What is the point of this whole system if it's not enforced?

If you want type checking, run mypy. If you don't want type checking, don't run mypy. I don't see what's so difficult. If it was technically possible to run programs that have type errors in other languages, they would have the option to ignore type errors too, because it's convenient. Typescript also ignores errors (generating js output for you to run) by default, so what's the point if it's not enforced?

Typescript does not ignore type errors by default. Type error = fail to compile

Re: Why if TYPE_CHECKING?

#74
post #72

Earlier quoted context omitted.

If you want type checking, run mypy. If you don't want type checking, don't run mypy. I don't see what's so difficult. If it was technically possible to run programs that have type errors in other languages, they would have the option to ignore type errors too, because it's convenient. Typescript also ignores errors (generating js output for you to run) by default, so what's the point if it's not enforced?

Typescript does not ignore type errors by default. Type error = fail to compile

Try it, it produces output by default. You have to add a flag/option to change this https://www.typescriptlang.org/tsconfig/#noEmitOnError
Post reply on HN