[Python-Dev] [python-committers] Enabling depreciation warnings feature code cutoff

Guido van Rossum guido at python.org
Sat Nov 11 20:47:20 EST 2017


On Sat, Nov 11, 2017 at 3:29 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> And given that one of the key benefits of static analysis is that it
> *doesn't* run the code, I'd be surprised if mypy could ever trigger a
> runtime warning in the code under tests :)
>

Actually there are a few cases where mypy *will* generate deprecation
warnings: when the warning is produced by the standard Python parser.
Mypy's parser (typed_ast) is a fork of the stdlib ast module and it
preserves the code that generates such warnings. I found two cases in
particular that generate them:

- In Python 2 code, the `<>` operator gives "DeprecationWarning: <> not
supported in 3.x; use !="/
- In Python 3 code, using `\u` escapes in a b'...' literal gives
"DeprecationWarning: invalid escape sequence '\u'"

In both cases these warnings are currently only generated if you run mypy
with these warnings enabled, e.g. `python3 -Wd -m mypy <files>`. But this
means that mypy would start generating these by default if those warnings
were enabled everywhere by default (per Antoine's preference). And while
it's debatable whether they are useful, there should at least be a way to
turn them off (e.g. when checking Python 2 code that's never going to be
ported). Running mypy in the above way is awkward; mypy would likely have
to grow a new flag to control this.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171111/6dcd1390/attachment-0001.html>


More information about the Python-Dev mailing list