https://github.com/asottile/pyupgrade/blob/fecacc91e57c224a0bd2564579ef01238650126c/pyupgrade.py#L53
if False: # pragma: no cover (mypy)
from typing import Type
if sys.version_info >= (3,):
AsyncFunctionDef = ast.AsyncFunctionDef
else:
AsyncFunctionDef = ast.stmt
The commit is not revealing: https://github.com/asottile/pyupgrade/commit/fecacc91e57c224a0bd2564579ef01238650126c#diff-8213eba6a28bcc759225cd8cf49b2fd1
False can be truthy in Python 2 (where it can be re-defined) but not in Python 3. It might be a joke, or work in progress, or way of commenting out the code, but this is quite a mature tool- am I missing something?
The value of AsyncFunctionDef is never needed at runtime, only by mypy in two Python-2-compatible type hints (at lines 1298 and 1318). The if False prevents the assignments from occurring at run-time, but lets mypy see the correct underlying type to use during type-checking. (It also prevents an ImportError from being raised at the attempt to import the typing module under Python 2.)
It would be clearer to use typing.TYPE_CHECKING (whose value is False at run-time, but True when mypy runs) here, except typing.TYPE_CHECKING is also unavailable in Python 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With