| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
As an exception, tests still don't do this since there are hundreds of tests that would have to be updated. If tests explicitly define command line options, strict optional will be on by default -- basically command line options in tests default to `--no-strict-optional`. Fixes #359.
There was a problem hiding this comment.
Thanks, looks good! Just some optional comments.
Sorry, something went wrong.
|
|
||
| If you don't know what types to add, you can use ``Any``, but beware: | ||
|
|
||
| - **One of the values involved has type ``Any``.** Extending the above |
There was a problem hiding this comment.
I think you can do something like **Text** ``Any`` **more text**. Then you will have both bold face and proper formatting for Any. (also below for None)
Sorry, something went wrong.
There was a problem hiding this comment.
Good idea, I'll give it a try.
Sorry, something went wrong.
There was a problem hiding this comment.
I'd just write 'Any'
Sorry, something went wrong.
| .. note:: | ||
|
|
||
| ``None`` is also used as the return type for functions that don't | ||
| return a value, i.e. that implicitly return ``None``. (Mypy doesn't |
There was a problem hiding this comment.
PEP 484 already specifies this, I am not sure we need to discuss this here again (on the other hand there was a recent issue that proposed to improve some wording there).
Sorry, something went wrong.
There was a problem hiding this comment.
Do you expect mypy users to read through PEP 484 (which is rather long and complex)? Especially for a fairly basic thing like this.
Sorry, something went wrong.
There was a problem hiding this comment.
I'd like the mypy documentation to be self-contained and PEP 484 should be strictly optional reading.
Sorry, something went wrong.
There was a problem hiding this comment.
Then I would reformulate this to make message more clear. Currently it starts from mentioning return type, but then moves to something else. Also I would not mention NoneType at all, it can only add to the confusion, I would just re-iterate that for simplicity None in type context means a type with a single value None. And separately mention that Python (this is not specific to mypy) returns None from a function that either reaches its end without return statement, or has a bare return.
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, NoneType never works in annotations. (Nor does type(None).) NoneType isn't even defined in the stdlib.
Sorry, something went wrong.
| if f == os.path.join('test-data', 'samples', 'crawl2.py'): | ||
| # This test requires 3.5 for async functions | ||
| driver.add_mypy_cmd('file {}'.format(f), ['--python-version=3.5', f]) | ||
| driver.add_mypy_cmd('file {}'.format(f), ['--python-version=3.5', |
There was a problem hiding this comment.
I am not sure we actually need the --python-version=3.5 flag. I thought mypy now uses the latest Python version by default.
Sorry, something went wrong.
There was a problem hiding this comment.
Unless I missed a PR, mypy uses the Python version uses sys.version_info of the executable used to run mypy, which still may be 3.4.
Sorry, something went wrong.
There was a problem hiding this comment.
Indeed, I was confused that the Python 3.6 syntax can be used in 2.7 stubs.
Sorry, something went wrong.
|
|
||
| If you don't know what types to add, you can use ``Any``, but beware: | ||
|
|
||
| - **One of the values involved has type ``Any``.** Extending the above |
There was a problem hiding this comment.
I'd just write 'Any'
Sorry, something went wrong.
| :ref:`optional` for details on strict optional checking, which allows mypy to | ||
| check ``None`` values precisely, and will soon become default. | ||
| You may have disabled strict optional checking (see | ||
| :ref:`no_strict_optional` for more). |
There was a problem hiding this comment.
I wonder if we should have a bullet for complaints about None as well. It will be a common issue for people who have used mypy with the default setting (for strict_optional anyway) before.
Sorry, something went wrong.
| generally check the use of ``None`` values -- they are valid | ||
| everywhere. See :ref:`strict_optional` for more about this feature. | ||
| This flag will become the default in the near future. | ||
| everywhere. See :ref:`no_strict_optional` for more about this feature. |
There was a problem hiding this comment.
Maybe mention that the default changed in mypy 0.600, like you do in the config file section about strict_optional.
Sorry, something went wrong.
|
|
||
| - ``strict_optional`` (Boolean, default True) enables or disables | ||
| strict Optional checks. If False, mypy treats ``None`` as | ||
| compatible with every type. This was False by default in mypy |
There was a problem hiding this comment.
**NOTE:** This was False ...
Sorry, something went wrong.
| doesn't treat primitives types | ||
| specially: ``None`` is also valid for primitive types such as ``int`` | ||
| and ``float``. | ||
| You can use the ``Optional`` type modifier to define a type variant |
There was a problem hiding this comment.
I'd start (redundantly) by noting that this is on by default as of 0.600.
Sorry, something went wrong.
|
|
||
| ``Optional[...]`` *does not* mean a function argument with a default value. | ||
| However, if the default value of an argument is ``None``, you can use | ||
| an optional type for the argument. |
There was a problem hiding this comment.
Maybe make this stronger? There's a flag --no-implicit-optional that requires using Optional[] here, and there's talk of deprecating the default behavior altogether.
Sorry, something went wrong.
|
|
||
| x = inc(None) # No error reported by mypy! | ||
|
|
||
| In mypy versions before 0.600 this was the default mode, and if you |
There was a problem hiding this comment.
Move this up?
Sorry, something went wrong.
| * Publish ``mypy-lang`` version 0.4.3 on PyPI. | ||
|
|
||
| * Add :ref:`strict_optional`. | ||
| * Add ``--strict-optional``. |
There was a problem hiding this comment.
Add link to chapter.
Sorry, something went wrong.
| parser.add_argument('--strict-optional', action='store_true', | ||
| help=argparse.SUPPRESS) | ||
| parser.add_argument('--no-strict-optional', action='store_false', dest='strict_optional', | ||
| help="disable strict Optional checks (inverse: --no-strict-optional)") |
There was a problem hiding this comment.
I think the inverse should be --strict-optional? Also can't this use add_invertible_flag()?
Sorry, something went wrong.
| if modules: | ||
| driver.add_mypy_modules('stdlibsamples (%s)' % (version,), modules, | ||
| cwd=stdlibsamples_dir) | ||
| cwd=stdlibsamples_dir, extra_args=['--no-strict-optional']) |
There was a problem hiding this comment.
Add the TODO here too?
Sorry, something went wrong.
Forgot to add these changes to #4971.
Forgot to add these changes to #4971.
| Back | FazBrowse Home | New Git URL |
As an exception, tests still don't do this since there are
hundreds of tests that would have to be updated. If tests
explicitly define command line options, strict optional will
be on by default -- basically command line options in tests
default to --no-strict-optional.
Fixes #359.