0

1) I'm running into a problem with my script using arguments parsed with argparse.ArgumentParser

so I'd like to be able to check typing of my script but when I add some arguments, I get a unrecognized arguments: --import_dir /tmp/someDir/ running

mypy myscript.py --import_dir /tmp/someDir

it seems that the arguments are passed to mypy and not myscript.py. Is there a way to get rid of that?

2) More than that, I'm using pyenv to set my version of python to be able to have types on a debian stable system. So if I run only my python script without arguments, I run into a Variable annotation syntax is only supported in Python 3.6 and greater problem because the system version is the stable debian version.

Pipo
  • 4,653
  • 38
  • 47
  • 1
    `mypy` doesn't run your script; it only does static analysis. – chepner Apr 21 '19 at 02:26
  • @chepner thats an answer... so is that that in the practice you'd run `mypy myscript.py && myscript.py` ??!!! no way with python to check typing another way!! – Pipo Apr 21 '19 at 09:17

1 Answers1

1

mypy is a tool for use during development. You typically don't run it at all in production, as the code itself isn't changed by deploying it. Any differences between your two environments should by definition be runtime changes, which mypy doesn't help with.

Assuming mypy myscript.py passes before deployment, it will continue to do so after, so there is no need to run it in production.

In the end, Python is and will remain a dynamically typed language; static type hinting is a tool for finding and preventing bugs, but doesn't affect how your code ultimately runs.

chepner
  • 497,756
  • 71
  • 530
  • 681