Skip to content

Commit b928db1

Browse files
authored
mypy environment needs a couple types pins added (#42927)
* mypy environment needs a few additional pins + the dev_requirements installed when it's running -- otherwise some types that come from optional dependencies won't resolve during type checking
1 parent f1eae2e commit b928db1

File tree

1 file changed

+15
-2
lines changed
  • eng/tools/azure-sdk-tools/azpysdk

1 file changed

+15
-2
lines changed

eng/tools/azure-sdk-tools/azpysdk/mypy.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
PYTHON_VERSION = "3.9"
1818
MYPY_VERSION = "1.14.1"
1919

20+
ADDITIONAL_LOCKED_DEPENDENCIES = [
21+
"types-chardet==5.0.4.6",
22+
"types-requests==2.31.0.6",
23+
"types-six==1.16.21.9",
24+
"types-redis==4.6.0.7",
25+
"PyGitHub>=1.59.0"
26+
]
2027

2128
class mypy(Check):
2229
def __init__(self) -> None:
@@ -45,17 +52,23 @@ def run(self, args: argparse.Namespace) -> int:
4552
for parsed in targeted:
4653
package_dir = parsed.folder
4754
package_name = parsed.name
55+
dev_requirements = os.path.join(package_dir, "dev_requirements.txt")
56+
additional_requirements = ADDITIONAL_LOCKED_DEPENDENCIES
4857

4958
executable, staging_directory = self.get_executable(args.isolate, args.command, sys.executable, package_dir)
5059
logger.info(f"Processing {package_name} for mypy check")
5160

61+
# # need to install dev_requirements to ensure that type-hints properly resolve
62+
if os.path.exists(dev_requirements):
63+
additional_requirements += ["-r", dev_requirements]
64+
5265
# install mypy
5366
try:
5467
if args.next:
5568
# use latest version of mypy
56-
install_into_venv(executable, ["mypy"])
69+
install_into_venv(executable, ["mypy"] + additional_requirements)
5770
else:
58-
install_into_venv(executable, [f"mypy=={MYPY_VERSION}"])
71+
install_into_venv(executable, [f"mypy=={MYPY_VERSION}"] + additional_requirements)
5972
except CalledProcessError as e:
6073
logger.error("Failed to install mypy:", e)
6174
return e.returncode

0 commit comments

Comments
 (0)