From e7816cc83fe4e277a0f1c9afff64774de9cbbd10 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Fri, 5 Nov 2021 19:25:42 -0500 Subject: [PATCH 1/4] unpin mypy Closes #1326 --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 849330b2802..83a6c8dd25d 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -6,7 +6,7 @@ coverage flake8 flake8-copyright isort==5.5.2 -mypy==0.790 +mypy nox packaging pre-commit From 27bd6fc3e44502090f734323ba4ea754d1f7dbe6 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Mon, 14 Feb 2022 09:37:16 -0600 Subject: [PATCH 2/4] noxfile and mypy.ini - check subdirs separately (https://github.com/python/mypy/issues/4008) - use mypy flags --install-types --non-interactive - fixup noxfile: use lint_plugins to run mypy on plugins - noxfile: run mypy on tools/ without --strict flag --- .mypy.ini | 4 ++++ noxfile.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index 384fcae9dbc..4c25b94361f 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -1,6 +1,10 @@ [mypy] python_version = 3.6 mypy_path=.stubs +exclude = (?x)( + build/ + | ^hydra/grammar/gen/ + ) [mypy-antlr4.*] ignore_missing_imports = True diff --git a/noxfile.py b/noxfile.py index de3be06dc87..99608be27d3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -233,11 +233,23 @@ def lint(session): session.run(*isort, silent=SILENT) - session.run("mypy", ".", "--strict", silent=SILENT) + session.run( + "mypy", + ".", + "--strict", + "--install-types", + "--non-interactive", + "--exclude=^examples/", + "--exclude=^tests/standalone_apps/", + "--exclude=^tests/test_apps/", + "--exclude=^tools/", + "--exclude=^plugins/", + silent=SILENT, + ) session.run("flake8", "--config", ".flake8") session.run("yamllint", "--strict", ".") - example_dirs = [ + mypy_check_subdirs = [ "examples/advanced", "examples/configure_hydra", "examples/patterns", @@ -245,11 +257,31 @@ def lint(session): "examples/tutorials/basic/your_first_hydra_app", "examples/tutorials/basic/running_your_hydra_app", "examples/tutorials/structured_configs", + "tests/standalone_apps", + "tests/test_apps", ] - for edir in example_dirs: - dirs = find_dirs(path=edir) + for sdir in mypy_check_subdirs: + dirs = find_dirs(path=sdir) for d in dirs: - session.run("mypy", d, "--strict", silent=SILENT) + session.run( + "mypy", + d, + "--strict", + "--install-types", + "--non-interactive", + silent=SILENT, + ) + + for sdir in ["tools"]: # no --strict flag for tools + dirs = find_dirs(path=sdir) + for d in dirs: + session.run( + "mypy", + d, + "--install-types", + "--non-interactive", + silent=SILENT, + ) # lint example plugins lint_plugins_in_dir(session=session, directory="examples/plugins") @@ -295,6 +327,8 @@ def lint_plugins_in_dir(session, directory: str) -> None: session.run( "mypy", "--strict", + "--install-types", + "--non-interactive", f"{path}/hydra_plugins", "--config-file", f"{BASE}/.mypy.ini", @@ -303,6 +337,8 @@ def lint_plugins_in_dir(session, directory: str) -> None: session.run( "mypy", "--strict", + "--install-types", + "--non-interactive", "--namespace-packages", "--config-file", f"{BASE}/.mypy.ini", From 2365aaa4ae5252b2af6f784b1e196f9cc2606b95 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Fri, 5 Nov 2021 19:29:10 -0500 Subject: [PATCH 3/4] fixup source files --- build_helpers/build_helpers.py | 12 +++++----- hydra/_internal/config_search_path_impl.py | 7 ++++-- .../importlib_resources_config_source.py | 22 ++++++++----------- hydra/core/config_search_path.py | 7 ++++-- hydra/core/plugins.py | 3 ++- hydra/extra/pytest_plugin.py | 16 +++++--------- tests/test_apps/app_change_dir/my_app.py | 2 +- .../custom_callback/my_app.py | 17 ++++++++------ .../multirun_structured_conflict/my_app.py | 2 +- .../1 => run_as_module_1}/config.yaml | 0 .../1 => run_as_module_1}/my_app.py | 0 .../2 => run_as_module_2}/conf/__init__.py | 0 .../2 => run_as_module_2}/conf/config.yaml | 0 .../2 => run_as_module_2}/my_app.py | 0 .../3 => run_as_module_3}/module/__init__.py | 0 .../module/conf/__init__.py | 0 .../3 => run_as_module_3}/module/config.yaml | 0 .../3 => run_as_module_3}/module/my_app.py | 0 .../4 => run_as_module_4}/module/__init__.py | 0 .../module/conf/__init__.py | 0 .../module/conf/config.yaml | 0 .../4 => run_as_module_4}/module/my_app.py | 0 .../__init__.py | 0 .../config.yaml | 0 .../group/a.yaml | 0 .../my_app.py | 0 .../structured_with_none_list/my_app.py | 4 +++- tests/test_hydra.py | 10 ++++----- tools/configen/configen/configen.py | 7 +++--- tools/configen/configen/utils.py | 6 ++--- tools/configen/example/__init__.py | 1 + tools/configen/example/config/__init__.py | 1 + .../example/config/configen/__init__.py | 1 + .../config/configen/samples/__init__.py | 1 + tools/configen/tests/test_generate.py | 5 +++-- .../tests/test_modules/future_annotations.py | 2 +- tools/release/release.py | 13 ++++++----- 37 files changed, 75 insertions(+), 64 deletions(-) rename tests/test_apps/{run_as_module/1 => run_as_module_1}/config.yaml (100%) rename tests/test_apps/{run_as_module/1 => run_as_module_1}/my_app.py (100%) rename tests/test_apps/{run_as_module/2 => run_as_module_2}/conf/__init__.py (100%) rename tests/test_apps/{run_as_module/2 => run_as_module_2}/conf/config.yaml (100%) rename tests/test_apps/{run_as_module/2 => run_as_module_2}/my_app.py (100%) rename tests/test_apps/{run_as_module/3 => run_as_module_3}/module/__init__.py (100%) rename tests/test_apps/{run_as_module/3 => run_as_module_3}/module/conf/__init__.py (100%) rename tests/test_apps/{run_as_module/3 => run_as_module_3}/module/config.yaml (100%) rename tests/test_apps/{run_as_module/3 => run_as_module_3}/module/my_app.py (100%) rename tests/test_apps/{run_as_module/4 => run_as_module_4}/module/__init__.py (100%) rename tests/test_apps/{run_as_module/4 => run_as_module_4}/module/conf/__init__.py (100%) rename tests/test_apps/{run_as_module/4 => run_as_module_4}/module/conf/config.yaml (100%) rename tests/test_apps/{run_as_module/4 => run_as_module_4}/module/my_app.py (100%) rename tests/test_apps/{schema-overrides-hydra => schema_overrides_hydra}/__init__.py (100%) rename tests/test_apps/{schema-overrides-hydra => schema_overrides_hydra}/config.yaml (100%) rename tests/test_apps/{schema-overrides-hydra => schema_overrides_hydra}/group/a.yaml (100%) rename tests/test_apps/{schema-overrides-hydra => schema_overrides_hydra}/my_app.py (100%) create mode 100644 tools/configen/example/__init__.py create mode 100644 tools/configen/example/config/__init__.py create mode 100644 tools/configen/example/config/configen/__init__.py create mode 100644 tools/configen/example/config/configen/samples/__init__.py diff --git a/build_helpers/build_helpers.py b/build_helpers/build_helpers.py index 157a0d60886..c6a511d576b 100644 --- a/build_helpers/build_helpers.py +++ b/build_helpers/build_helpers.py @@ -10,7 +10,7 @@ from typing import List, Optional from setuptools import Command -from setuptools.command import build_py, develop, sdist # type: ignore +from setuptools.command import build_py, develop, sdist def find_version(*file_paths: str) -> str: @@ -143,7 +143,7 @@ def run_antlr(cmd: Command) -> None: raise -class BuildPyCommand(build_py.build_py): # type: ignore +class BuildPyCommand(build_py.build_py): def run(self) -> None: if not self.dry_run: self.run_command("clean") @@ -151,16 +151,16 @@ def run(self) -> None: build_py.build_py.run(self) -class Develop(develop.develop): # type: ignore - def run(self) -> None: +class Develop(develop.develop): + def run(self) -> None: # type: ignore if not self.dry_run: run_antlr(self) develop.develop.run(self) -class SDistCommand(sdist.sdist): # type: ignore +class SDistCommand(sdist.sdist): def run(self) -> None: - if not self.dry_run: + if not self.dry_run: # type: ignore self.run_command("clean") run_antlr(self) sdist.sdist.run(self) diff --git a/hydra/_internal/config_search_path_impl.py b/hydra/_internal/config_search_path_impl.py index ab186e07b13..d0d7131f476 100644 --- a/hydra/_internal/config_search_path_impl.py +++ b/hydra/_internal/config_search_path_impl.py @@ -1,5 +1,5 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved -from typing import List, MutableSequence, Optional +from typing import List, MutableSequence, Optional, Union from hydra.core.config_search_path import ( ConfigSearchPath, @@ -63,7 +63,10 @@ def append( self.append(provider, path, anchor=None) def prepend( - self, provider: str, path: str, anchor: Optional[SearchPathQuery] = None + self, + provider: str, + path: str, + anchor: Optional[Union[SearchPathQuery, str]] = None, ) -> None: """ Prepends to the search path. diff --git a/hydra/_internal/core_plugins/importlib_resources_config_source.py b/hydra/_internal/core_plugins/importlib_resources_config_source.py index 0972d7ea074..efd894bfc3b 100644 --- a/hydra/_internal/core_plugins/importlib_resources_config_source.py +++ b/hydra/_internal/core_plugins/importlib_resources_config_source.py @@ -2,19 +2,17 @@ import os import sys import zipfile -from typing import Any, List, Optional +from typing import TYPE_CHECKING, Any, List, Optional from omegaconf import OmegaConf from hydra.core.object_type import ObjectType from hydra.plugins.config_source import ConfigLoadError, ConfigResult, ConfigSource -if sys.version_info.major >= 4 or ( - sys.version_info.major >= 3 and sys.version_info.minor >= 9 -): - from importlib import resources +if TYPE_CHECKING or (sys.version_info < (3, 9)): + import importlib_resources as resources else: - import importlib_resources as resources # type:ignore + from importlib import resources # Relevant issue: https://github.com/python/mypy/issues/1153 # Use importlib backport for Python older than 3.9 @@ -55,7 +53,7 @@ def _read_config(self, res: Any) -> ConfigResult: def load_config(self, config_path: str) -> ConfigResult: normalized_config_path = self._normalize_file_name(config_path) - res = resources.files(self.path).joinpath(normalized_config_path) # type:ignore + res = resources.files(self.path).joinpath(normalized_config_path) if not res.exists(): raise ConfigLoadError(f"Config not found : {normalized_config_path}") @@ -63,14 +61,14 @@ def load_config(self, config_path: str) -> ConfigResult: def available(self) -> bool: try: - files = resources.files(self.path) # type: ignore + files = resources.files(self.path) except (ValueError, ModuleNotFoundError, TypeError): return False return any(f.name == "__init__.py" and f.is_file() for f in files.iterdir()) def is_group(self, config_path: str) -> bool: try: - files = resources.files(self.path) # type:ignore + files = resources.files(self.path) except (ValueError, ModuleNotFoundError, TypeError): return False @@ -82,7 +80,7 @@ def is_group(self, config_path: str) -> bool: def is_config(self, config_path: str) -> bool: config_path = self._normalize_file_name(config_path) try: - files = resources.files(self.path) # type:ignore + files = resources.files(self.path) except (ValueError, ModuleNotFoundError, TypeError): return False res = files.joinpath(config_path) @@ -92,9 +90,7 @@ def is_config(self, config_path: str) -> bool: def list(self, config_path: str, results_filter: Optional[ObjectType]) -> List[str]: files: List[str] = [] - for file in ( - resources.files(self.path).joinpath(config_path).iterdir() # type:ignore - ): + for file in resources.files(self.path).joinpath(config_path).iterdir(): fname = file.name fpath = os.path.join(config_path, fname) self._list_add_result( diff --git a/hydra/core/config_search_path.py b/hydra/core/config_search_path.py index b2e9772fbe2..dd43a08499a 100644 --- a/hydra/core/config_search_path.py +++ b/hydra/core/config_search_path.py @@ -1,7 +1,7 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from abc import ABC, abstractmethod from dataclasses import dataclass -from typing import MutableSequence, Optional +from typing import MutableSequence, Optional, Union class SearchPathElement: @@ -49,7 +49,10 @@ def append( @abstractmethod def prepend( - self, provider: str, path: str, anchor: Optional[SearchPathQuery] = None + self, + provider: str, + path: str, + anchor: Optional[Union[SearchPathQuery, str]] = None, ) -> None: """ Prepends to the search path. diff --git a/hydra/core/plugins.py b/hydra/core/plugins.py index 20425d7b210..65ea92f7d9f 100644 --- a/hydra/core/plugins.py +++ b/hydra/core/plugins.py @@ -167,7 +167,8 @@ def _scan_all_plugins( if module_name.startswith("_") and not module_name.startswith("__"): continue import_time = timer() - m = importer.find_module(modname) + m = importer.find_module(modname) # type: ignore + assert m is not None with warnings.catch_warnings(record=True) as recorded_warnings: loaded_mod = m.load_module(modname) import_time = timer() - import_time diff --git a/hydra/extra/pytest_plugin.py b/hydra/extra/pytest_plugin.py index 522a6c76338..f01d5dbca93 100644 --- a/hydra/extra/pytest_plugin.py +++ b/hydra/extra/pytest_plugin.py @@ -1,7 +1,7 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import copy from pathlib import Path -from typing import Callable, List, Optional +from typing import Callable, Generator, List, Optional from pytest import fixture @@ -10,8 +10,8 @@ from hydra.types import TaskFunction -@fixture(scope="function") # type: ignore -def hydra_restore_singletons() -> None: +@fixture(scope="function") +def hydra_restore_singletons() -> Generator[None, None, None]: """ Restore singletons state after the function returns """ @@ -20,7 +20,7 @@ def hydra_restore_singletons() -> None: Singleton.set_state(state) -@fixture(scope="function") # type: ignore +@fixture(scope="function") def hydra_sweep_runner() -> Callable[ [ Optional[str], @@ -29,7 +29,6 @@ def hydra_sweep_runner() -> Callable[ Optional[str], Optional[str], Optional[List[str]], - Optional[bool], Optional[Path], bool, ], @@ -42,7 +41,6 @@ def _( config_path: Optional[str], config_name: Optional[str], overrides: Optional[List[str]], - strict: Optional[bool] = None, temp_dir: Optional[Path] = None, configure_logging: bool = False, ) -> SweepTaskFunction: @@ -52,7 +50,6 @@ def _( sweep.task_function = task_function sweep.config_path = config_path sweep.config_name = config_name - sweep.strict = strict sweep.overrides = overrides or [] sweep.temp_dir = str(temp_dir) sweep.configure_logging = configure_logging @@ -61,7 +58,7 @@ def _( return _ -@fixture(scope="function") # type: ignore +@fixture(scope="function") def hydra_task_runner() -> Callable[ [ Optional[str], @@ -69,7 +66,6 @@ def hydra_task_runner() -> Callable[ Optional[str], Optional[str], Optional[List[str]], - Optional[bool], bool, ], TaskTestFunction, @@ -80,7 +76,6 @@ def _( config_path: Optional[str], config_name: Optional[str], overrides: Optional[List[str]] = None, - strict: Optional[bool] = None, configure_logging: bool = False, ) -> TaskTestFunction: task = TaskTestFunction() @@ -89,7 +84,6 @@ def _( task.config_name = config_name task.calling_module = calling_module task.config_path = config_path - task.strict = strict task.configure_logging = configure_logging return task diff --git a/tests/test_apps/app_change_dir/my_app.py b/tests/test_apps/app_change_dir/my_app.py index 4ce09eac118..e5834da0341 100644 --- a/tests/test_apps/app_change_dir/my_app.py +++ b/tests/test_apps/app_change_dir/my_app.py @@ -9,7 +9,7 @@ @hydra.main(config_path=None) -def main(_: DictConfig): +def main(_: DictConfig) -> None: subdir = Path(HydraConfig.get().run.dir) / Path("subdir") subdir.mkdir(exist_ok=True, parents=True) os.chdir(subdir) diff --git a/tests/test_apps/app_with_callbacks/custom_callback/my_app.py b/tests/test_apps/app_with_callbacks/custom_callback/my_app.py index 6854379a3c2..6f7698c458a 100644 --- a/tests/test_apps/app_with_callbacks/custom_callback/my_app.py +++ b/tests/test_apps/app_with_callbacks/custom_callback/my_app.py @@ -1,6 +1,7 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import logging +from typing import Any from omegaconf import DictConfig, OmegaConf @@ -12,26 +13,28 @@ class CustomCallback(Callback): - def __init__(self, callback_name): + def __init__(self, callback_name: str) -> None: self.name = callback_name log.info(f"Init {self.name}") - def on_job_start(self, config: DictConfig, **kwargs) -> None: + def on_job_start(self, config: DictConfig, **kwargs: Any) -> None: log.info(f"{self.name} on_job_start") - def on_job_end(self, config: DictConfig, job_return: JobReturn, **kwargs) -> None: + def on_job_end( + self, config: DictConfig, job_return: JobReturn, **kwargs: Any + ) -> None: log.info(f"{self.name} on_job_end") - def on_run_start(self, config: DictConfig, **kwargs) -> None: + def on_run_start(self, config: DictConfig, **kwargs: Any) -> None: log.info(f"{self.name} on_run_start") - def on_run_end(self, config: DictConfig, **kwargs) -> None: + def on_run_end(self, config: DictConfig, **kwargs: Any) -> None: log.info(f"{self.name} on_run_end") - def on_multirun_start(self, config: DictConfig, **kwargs) -> None: + def on_multirun_start(self, config: DictConfig, **kwargs: Any) -> None: log.info(f"{self.name} on_multirun_start") - def on_multirun_end(self, config: DictConfig, **kwargs) -> None: + def on_multirun_end(self, config: DictConfig, **kwargs: Any) -> None: log.info(f"{self.name} on_multirun_end") diff --git a/tests/test_apps/multirun_structured_conflict/my_app.py b/tests/test_apps/multirun_structured_conflict/my_app.py index 008c3a2a26b..89cec023767 100644 --- a/tests/test_apps/multirun_structured_conflict/my_app.py +++ b/tests/test_apps/multirun_structured_conflict/my_app.py @@ -17,7 +17,7 @@ class TestConfig: @hydra.main(config_path=".", config_name="config") -def run(config: DictConfig): +def run(config: DictConfig) -> None: print(config.test.param) diff --git a/tests/test_apps/run_as_module/1/config.yaml b/tests/test_apps/run_as_module_1/config.yaml similarity index 100% rename from tests/test_apps/run_as_module/1/config.yaml rename to tests/test_apps/run_as_module_1/config.yaml diff --git a/tests/test_apps/run_as_module/1/my_app.py b/tests/test_apps/run_as_module_1/my_app.py similarity index 100% rename from tests/test_apps/run_as_module/1/my_app.py rename to tests/test_apps/run_as_module_1/my_app.py diff --git a/tests/test_apps/run_as_module/2/conf/__init__.py b/tests/test_apps/run_as_module_2/conf/__init__.py similarity index 100% rename from tests/test_apps/run_as_module/2/conf/__init__.py rename to tests/test_apps/run_as_module_2/conf/__init__.py diff --git a/tests/test_apps/run_as_module/2/conf/config.yaml b/tests/test_apps/run_as_module_2/conf/config.yaml similarity index 100% rename from tests/test_apps/run_as_module/2/conf/config.yaml rename to tests/test_apps/run_as_module_2/conf/config.yaml diff --git a/tests/test_apps/run_as_module/2/my_app.py b/tests/test_apps/run_as_module_2/my_app.py similarity index 100% rename from tests/test_apps/run_as_module/2/my_app.py rename to tests/test_apps/run_as_module_2/my_app.py diff --git a/tests/test_apps/run_as_module/3/module/__init__.py b/tests/test_apps/run_as_module_3/module/__init__.py similarity index 100% rename from tests/test_apps/run_as_module/3/module/__init__.py rename to tests/test_apps/run_as_module_3/module/__init__.py diff --git a/tests/test_apps/run_as_module/3/module/conf/__init__.py b/tests/test_apps/run_as_module_3/module/conf/__init__.py similarity index 100% rename from tests/test_apps/run_as_module/3/module/conf/__init__.py rename to tests/test_apps/run_as_module_3/module/conf/__init__.py diff --git a/tests/test_apps/run_as_module/3/module/config.yaml b/tests/test_apps/run_as_module_3/module/config.yaml similarity index 100% rename from tests/test_apps/run_as_module/3/module/config.yaml rename to tests/test_apps/run_as_module_3/module/config.yaml diff --git a/tests/test_apps/run_as_module/3/module/my_app.py b/tests/test_apps/run_as_module_3/module/my_app.py similarity index 100% rename from tests/test_apps/run_as_module/3/module/my_app.py rename to tests/test_apps/run_as_module_3/module/my_app.py diff --git a/tests/test_apps/run_as_module/4/module/__init__.py b/tests/test_apps/run_as_module_4/module/__init__.py similarity index 100% rename from tests/test_apps/run_as_module/4/module/__init__.py rename to tests/test_apps/run_as_module_4/module/__init__.py diff --git a/tests/test_apps/run_as_module/4/module/conf/__init__.py b/tests/test_apps/run_as_module_4/module/conf/__init__.py similarity index 100% rename from tests/test_apps/run_as_module/4/module/conf/__init__.py rename to tests/test_apps/run_as_module_4/module/conf/__init__.py diff --git a/tests/test_apps/run_as_module/4/module/conf/config.yaml b/tests/test_apps/run_as_module_4/module/conf/config.yaml similarity index 100% rename from tests/test_apps/run_as_module/4/module/conf/config.yaml rename to tests/test_apps/run_as_module_4/module/conf/config.yaml diff --git a/tests/test_apps/run_as_module/4/module/my_app.py b/tests/test_apps/run_as_module_4/module/my_app.py similarity index 100% rename from tests/test_apps/run_as_module/4/module/my_app.py rename to tests/test_apps/run_as_module_4/module/my_app.py diff --git a/tests/test_apps/schema-overrides-hydra/__init__.py b/tests/test_apps/schema_overrides_hydra/__init__.py similarity index 100% rename from tests/test_apps/schema-overrides-hydra/__init__.py rename to tests/test_apps/schema_overrides_hydra/__init__.py diff --git a/tests/test_apps/schema-overrides-hydra/config.yaml b/tests/test_apps/schema_overrides_hydra/config.yaml similarity index 100% rename from tests/test_apps/schema-overrides-hydra/config.yaml rename to tests/test_apps/schema_overrides_hydra/config.yaml diff --git a/tests/test_apps/schema-overrides-hydra/group/a.yaml b/tests/test_apps/schema_overrides_hydra/group/a.yaml similarity index 100% rename from tests/test_apps/schema-overrides-hydra/group/a.yaml rename to tests/test_apps/schema_overrides_hydra/group/a.yaml diff --git a/tests/test_apps/schema-overrides-hydra/my_app.py b/tests/test_apps/schema_overrides_hydra/my_app.py similarity index 100% rename from tests/test_apps/schema-overrides-hydra/my_app.py rename to tests/test_apps/schema_overrides_hydra/my_app.py diff --git a/tests/test_apps/structured_with_none_list/my_app.py b/tests/test_apps/structured_with_none_list/my_app.py index 4b6188d129e..212939e8d93 100644 --- a/tests/test_apps/structured_with_none_list/my_app.py +++ b/tests/test_apps/structured_with_none_list/my_app.py @@ -2,6 +2,8 @@ from dataclasses import dataclass from typing import List, Optional +from omegaconf import DictConfig + import hydra from hydra.core.config_store import ConfigStore @@ -16,7 +18,7 @@ class Config: @hydra.main(config_path=None, config_name="config") -def main(cfg): +def main(cfg: DictConfig) -> None: print(cfg) diff --git a/tests/test_hydra.py b/tests/test_hydra.py index 6064f4ea37e..a71bd2c6fc0 100644 --- a/tests/test_hydra.py +++ b/tests/test_hydra.py @@ -1031,14 +1031,14 @@ def test_hydra_output_dir( "directory,file,module, error", [ ( - "tests/test_apps/run_as_module/1", + "tests/test_apps/run_as_module_1", "my_app.py", "my_app", "Primary config module is empty", ), - ("tests/test_apps/run_as_module/2", "my_app.py", "my_app", None), - ("tests/test_apps/run_as_module/3", "module/my_app.py", "module.my_app", None), - ("tests/test_apps/run_as_module/4", "module/my_app.py", "module.my_app", None), + ("tests/test_apps/run_as_module_2", "my_app.py", "my_app", None), + ("tests/test_apps/run_as_module_3", "module/my_app.py", "module.my_app", None), + ("tests/test_apps/run_as_module_4", "module/my_app.py", "module.my_app", None), ], ) def test_module_run( @@ -1285,7 +1285,7 @@ def test_config_dir_argument( def test_schema_overrides_hydra(monkeypatch: Any, tmpdir: Path) -> None: - monkeypatch.chdir("tests/test_apps/schema-overrides-hydra") + monkeypatch.chdir("tests/test_apps/schema_overrides_hydra") cmd = [ "my_app.py", "hydra.run.dir=" + str(tmpdir), diff --git a/tools/configen/configen/configen.py b/tools/configen/configen/configen.py index 21a3e7a2d9d..3212175030e 100644 --- a/tools/configen/configen/configen.py +++ b/tools/configen/configen/configen.py @@ -57,6 +57,7 @@ def init_config(conf_dir: str) -> None: sys.exit(1) sample_config = pkgutil.get_data(__name__, "templates/sample_config.yaml") + assert sample_config is not None file.write_bytes(sample_config) @@ -147,7 +148,7 @@ def get_default_flags(module: ModuleConf) -> List[Parameter]: Parameter( name="_recursive_", type_str="bool", - default=module.default_flags._recursive_, + default=str(module.default_flags._recursive_), ) ) @@ -156,7 +157,7 @@ def get_default_flags(module: ModuleConf) -> List[Parameter]: def generate_module(cfg: ConfigenConf, module: ModuleConf) -> str: classes_map: Dict[str, ClassInfo] = {} - imports = set() + imports: Set[Any] = set() string_imports: Set[str] = set() default_flags = get_default_flags(module) @@ -165,7 +166,7 @@ def generate_module(cfg: ConfigenConf, module: ModuleConf) -> str: full_name = f"{module.name}.{class_name}" cls = hydra.utils.get_class(full_name) sig = inspect.signature(cls) - resolved_hints = get_type_hints(cls.__init__) + resolved_hints = get_type_hints(cls.__init__) # type: ignore params: List[Parameter] = [] params = params + default_flags diff --git a/tools/configen/configen/utils.py b/tools/configen/configen/utils.py index fc7e624e9b1..f102a42970b 100644 --- a/tools/configen/configen/utils.py +++ b/tools/configen/configen/utils.py @@ -1,7 +1,7 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import sys from enum import Enum -from typing import Any, Dict, List, Optional, Set, Tuple, Type +from typing import Any, Dict, Iterable, List, Optional, Set, Tuple from omegaconf._utils import ( _resolve_optional, @@ -65,7 +65,7 @@ def is_tuple_annotation(type_: Any) -> bool: return origin is tuple # pragma: no cover -def convert_imports(imports: Set[Type], string_imports: List[str]) -> List[str]: +def convert_imports(imports: Set[Any], string_imports: Iterable[str]) -> List[str]: tmp = set() for imp in string_imports: tmp.add(imp) @@ -94,7 +94,7 @@ def convert_imports(imports: Set[Type], string_imports: List[str]) -> List[str]: return sorted(list(tmp)) -def collect_imports(imports: Set[Type], type_: Type) -> None: +def collect_imports(imports: Set[Any], type_: Any) -> None: if is_list_annotation(type_): collect_imports(imports, get_list_element_type(type_)) type_ = List diff --git a/tools/configen/example/__init__.py b/tools/configen/example/__init__.py new file mode 100644 index 00000000000..168f9979a46 --- /dev/null +++ b/tools/configen/example/__init__.py @@ -0,0 +1 @@ +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved diff --git a/tools/configen/example/config/__init__.py b/tools/configen/example/config/__init__.py new file mode 100644 index 00000000000..168f9979a46 --- /dev/null +++ b/tools/configen/example/config/__init__.py @@ -0,0 +1 @@ +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved diff --git a/tools/configen/example/config/configen/__init__.py b/tools/configen/example/config/configen/__init__.py new file mode 100644 index 00000000000..168f9979a46 --- /dev/null +++ b/tools/configen/example/config/configen/__init__.py @@ -0,0 +1 @@ +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved diff --git a/tools/configen/example/config/configen/samples/__init__.py b/tools/configen/example/config/configen/samples/__init__.py new file mode 100644 index 00000000000..168f9979a46 --- /dev/null +++ b/tools/configen/example/config/configen/samples/__init__.py @@ -0,0 +1 @@ +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved diff --git a/tools/configen/tests/test_generate.py b/tools/configen/tests/test_generate.py index 6fc5f339b37..10f339bd947 100644 --- a/tools/configen/tests/test_generate.py +++ b/tools/configen/tests/test_generate.py @@ -194,7 +194,7 @@ def test_generated_code_with_default_flags( {"param": "str"}, [], {}, - UnionArg(param="str"), + UnionArg(param="str"), # type: ignore id="UnionArg:illegal_but_ok_arg", ), param( @@ -280,7 +280,8 @@ def test_instantiate_classes( full_class = f"{MODULE_NAME}.generated.{classname}Conf" schema = OmegaConf.structured(get_class(full_class)) cfg = OmegaConf.merge(schema, params) - obj = instantiate(config=cfg, *args, **kwargs) + kwargs["config"] = cfg + obj = instantiate(*args, **kwargs) assert obj == expected diff --git a/tools/configen/tests/test_modules/future_annotations.py b/tools/configen/tests/test_modules/future_annotations.py index c0b3d0c2b1c..79591658b4b 100644 --- a/tools/configen/tests/test_modules/future_annotations.py +++ b/tools/configen/tests/test_modules/future_annotations.py @@ -1,5 +1,5 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved -from __future__ import annotations # noqa: F407 +from __future__ import annotations # type: ignore # noqa: F407 from dataclasses import dataclass from typing import List, Optional diff --git a/tools/release/release.py b/tools/release/release.py index 5a5468c46db..0bb39bedfed 100644 --- a/tools/release/release.py +++ b/tools/release/release.py @@ -72,7 +72,7 @@ def get_releases(metadata: DictConfig) -> List[Version]: @dataclass -class Package: +class PackageInfo: name: str local_version: Version latest_version: Version @@ -84,7 +84,7 @@ def parse_version(ver: str) -> Version: return v -def get_package_info(path: str) -> Package: +def get_package_info(path: str) -> PackageInfo: try: prev = os.getcwd() path = os.path.abspath(path) @@ -101,7 +101,7 @@ def get_package_info(path: str) -> Package: remote_metadata = get_metadata(package_name) latest = get_releases(remote_metadata)[-1] - return Package( + return PackageInfo( name=package_name, local_version=local_version, latest_version=latest ) @@ -123,17 +123,20 @@ def build_package(cfg: Config, pkg_path: str, build_dir: str) -> None: def _next_version(version: str) -> str: cur = parse(version) + assert isinstance(cur, Version) if cur.is_devrelease: prefix = "dev" + assert cur.dev is not None num = cur.dev + 1 new_version = f"{cur.major}.{cur.minor}.{cur.micro}.{prefix}{num}" elif cur.is_prerelease: + assert cur.pre is not None prefix = cur.pre[0] num = cur.pre[1] + 1 new_version = f"{cur.major}.{cur.minor}.{cur.micro}.{prefix}{num}" elif cur.is_postrelease: - prefix = cur.post[0] - num = cur.post[1] + 1 + assert cur.post is not None + num = cur.post + 1 new_version = f"{cur.major}.{cur.minor}.{cur.micro}.{prefix}{num}" else: micro = cur.micro + 1 From f0d30ae370a0cd2faed886fcba7070ee91a40fa9 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Mon, 14 Feb 2022 17:38:47 -0600 Subject: [PATCH 4/4] Fix bad f-string interpolation See comment https://github.com/facebookresearch/hydra/pull/1878#discussion_r806284604 --- tools/release/release.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/release/release.py b/tools/release/release.py index 0bb39bedfed..6c0cd6e6fd1 100644 --- a/tools/release/release.py +++ b/tools/release/release.py @@ -137,7 +137,7 @@ def _next_version(version: str) -> str: elif cur.is_postrelease: assert cur.post is not None num = cur.post + 1 - new_version = f"{cur.major}.{cur.minor}.{cur.micro}.{prefix}{num}" + new_version = f"{cur.major}.{cur.minor}.{cur.micro}.{num}" else: micro = cur.micro + 1 new_version = f"{cur.major}.{cur.minor}.{micro}"