From d68c526f65a12a1c8a9b7dcff613fce15675a29d Mon Sep 17 00:00:00 2001 From: Matt Glazar Date: Fri, 26 Jul 2019 14:16:11 -0700 Subject: [PATCH] Fix flake8 with Python 2.7 Summary: flake8 (in Python 2.7 mode) complains that `typing` is mentioned in type annotations but is not defined: ``` fbcode_builder/getdeps/buildopts.py:251:21: F821 undefined name 'typing' subst_mapping, # type: typing.Mapping[str, str] ^ fbcode_builder/getdeps/buildopts.py:253:5: F821 undefined name 'typing' # type: (...) -> typing.Optional[str] ^ 2 F821 undefined name 'typing' 2 ``` Import `typing` explicitly to silence this warning. Because `typing` may be unavailable, import it conditionally. (Because it's only referenced in comments, failing to import `typing` should have no effect at run time.) Reviewed By: snarkmaster Differential Revision: D16435696 fbshipit-source-id: 78a4a7b07acc46aa998f02b54b1a6e52c1daafde --- build/fbcode_builder/getdeps/buildopts.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/fbcode_builder/getdeps/buildopts.py b/build/fbcode_builder/getdeps/buildopts.py index e8bac5f8e..dd551af62 100644 --- a/build/fbcode_builder/getdeps/buildopts.py +++ b/build/fbcode_builder/getdeps/buildopts.py @@ -21,6 +21,12 @@ from .envfuncs import Env, add_path_entry, path_search from .platform import HostType, is_windows +try: + import typing # noqa: F401 +except ImportError: + pass + + def containing_repo_type(path): while True: if os.path.exists(os.path.join(path, ".git")):