From 1c964719ece6652c7116099f4fb90656f0f4ca6a Mon Sep 17 00:00:00 2001 From: mdemello Date: Tue, 19 Mar 2024 16:58:50 +0000 Subject: [PATCH] Move error code into its own subpackage PiperOrigin-RevId: 617206722 --- pytype/CMakeLists.txt | 46 ++++++---------------------- pytype/config.py | 2 +- pytype/context.py | 2 +- pytype/directors/CMakeLists.txt | 2 +- pytype/directors/directors_test.py | 2 +- pytype/errors/CMakeLists.txt | 38 +++++++++++++++++++++++ pytype/errors/__init__.py | 0 pytype/{ => errors}/error_printer.py | 0 pytype/{ => errors}/errors.py | 2 +- pytype/{ => errors}/errors_test.py | 5 +-- pytype/rewrite/CMakeLists.txt | 2 +- pytype/rewrite/analyze.py | 2 +- pytype/tests/test_base_test.py | 2 +- 13 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 pytype/errors/CMakeLists.txt create mode 100644 pytype/errors/__init__.py rename pytype/{ => errors}/error_printer.py (100%) rename pytype/{ => errors}/errors.py (99%) rename pytype/{ => errors}/errors_test.py (99%) diff --git a/pytype/CMakeLists.txt b/pytype/CMakeLists.txt index b4cc81c56..fc4218c62 100644 --- a/pytype/CMakeLists.txt +++ b/pytype/CMakeLists.txt @@ -5,9 +5,9 @@ py_library( api DEPS .config - .errors .io .load_pytd + pytype.errors.errors ) toplevel_py_binary( @@ -41,29 +41,14 @@ py_library( DEPS ._utils .datatypes - .errors .file_utils .imports_map_loader .module_utils + pytype.errors.errors pytype.pyc.pyc pytype.typegraph.cfg_utils ) -py_library( - NAME - errors - SRCS - errors.py - DEPS - ._utils - .debug - .error_printer - .pretty_printer - pytype.abstract.abstract - pytype.overlays.overlays - pytype.pytd.pytd -) - py_library( NAME load_pytd @@ -102,7 +87,6 @@ py_library( .convert .convert_structural .debug - .errors .imports_map_loader .io .load_pytd @@ -113,6 +97,7 @@ py_library( .tracer_vm .vm pytype.directors.directors + pytype.errors.errors ) py_library( @@ -126,20 +111,6 @@ py_library( pytype.typegraph.cfg ) -py_library( - NAME - error_printer - SRCS - error_printer.py - DEPS - .matcher - .pretty_printer - pytype.abstract.abstract - pytype.overlays.overlays - pytype.pytd.pytd - pytype.typegraph.cfg -) - filegroup( NAME test_data @@ -253,13 +224,13 @@ py_library( .attribute .config .convert - .errors .load_pytd .matcher .output .tracer_vm .vm_utils pytype.abstract.abstract + pytype.errors.errors pytype.overlays.overlays pytype.typegraph.cfg pytype.typegraph.cfg_utils @@ -512,8 +483,8 @@ py_test( typegraph_metrics_test.py DEPS .context - .errors .vm + pytype.errors.errors pytype.tests.test_base pytype.typegraph.cfg ) @@ -600,9 +571,9 @@ py_test( .compare .config .context - .errors .load_pytd pytype.abstract.abstract + pytype.errors.errors pytype.pytd.pytd pytype.tests.test_base ) @@ -638,9 +609,9 @@ py_test( DEPS .config .context - .errors .load_pytd pytype.abstract.abstract + pytype.errors.errors pytype.tests.test_base ) @@ -662,12 +633,12 @@ py_test( .config .constant_folding .context - .errors .load_pytd .state pytype.abstract.abstract pytype.blocks.blocks pytype.directors.directors + pytype.errors.errors pytype.pyc.pyc pytype.pytd.pytd pytype.tests.test_base @@ -776,6 +747,7 @@ add_subdirectory(abstract) add_subdirectory(ast) add_subdirectory(blocks) add_subdirectory(directors) +add_subdirectory(errors) add_subdirectory(imports) add_subdirectory(inspect) add_subdirectory(overlays) diff --git a/pytype/config.py b/pytype/config.py index 67ef25f21..73daa14b5 100644 --- a/pytype/config.py +++ b/pytype/config.py @@ -12,11 +12,11 @@ from typing import List, overload from pytype import datatypes -from pytype import errors from pytype import file_utils from pytype import imports_map_loader from pytype import module_utils from pytype import utils +from pytype.errors import errors from pytype.pyc import compiler from pytype.typegraph import cfg_utils diff --git a/pytype/context.py b/pytype/context.py index 839dc4a38..ddb9cba5f 100644 --- a/pytype/context.py +++ b/pytype/context.py @@ -8,7 +8,6 @@ from pytype import attribute from pytype import config from pytype import convert -from pytype import errors from pytype import load_pytd from pytype import matcher from pytype import output @@ -17,6 +16,7 @@ from pytype.abstract import abstract from pytype.abstract import abstract_utils from pytype.abstract import function +from pytype.errors import errors from pytype.overlays import special_builtins from pytype.typegraph import cfg from pytype.typegraph import cfg_utils diff --git a/pytype/directors/CMakeLists.txt b/pytype/directors/CMakeLists.txt index 19bc5ee49..1078ea006 100644 --- a/pytype/directors/CMakeLists.txt +++ b/pytype/directors/CMakeLists.txt @@ -62,5 +62,5 @@ py_test( directors_test.py DEPS .directors - pytype.errors + pytype.errors.errors ) diff --git a/pytype/directors/directors_test.py b/pytype/directors/directors_test.py index d90637a63..fa8e5b531 100644 --- a/pytype/directors/directors_test.py +++ b/pytype/directors/directors_test.py @@ -3,8 +3,8 @@ import sys import textwrap -from pytype import errors from pytype.directors import directors +from pytype.errors import errors import unittest _TEST_FILENAME = "my_file.py" diff --git a/pytype/errors/CMakeLists.txt b/pytype/errors/CMakeLists.txt new file mode 100644 index 000000000..eb2e34145 --- /dev/null +++ b/pytype/errors/CMakeLists.txt @@ -0,0 +1,38 @@ +add_package() + +py_library( + NAME + errors + DEPS + ._errors + .error_printer +) + +py_library( + NAME + _errors + SRCS + errors.py + DEPS + .error_printer + pytype._utils + pytype.debug + pytype.pretty_printer + pytype.abstract.abstract + pytype.overlays.overlays + pytype.pytd.pytd +) + +py_library( + NAME + error_printer + SRCS + error_printer.py + DEPS + pytype.matcher + pytype.pretty_printer + pytype.abstract.abstract + pytype.overlays.overlays + pytype.pytd.pytd + pytype.typegraph.cfg +) diff --git a/pytype/errors/__init__.py b/pytype/errors/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pytype/error_printer.py b/pytype/errors/error_printer.py similarity index 100% rename from pytype/error_printer.py rename to pytype/errors/error_printer.py diff --git a/pytype/errors.py b/pytype/errors/errors.py similarity index 99% rename from pytype/errors.py rename to pytype/errors/errors.py index a190d6b38..791bd3bd0 100644 --- a/pytype/errors.py +++ b/pytype/errors/errors.py @@ -8,11 +8,11 @@ from typing import Callable, IO, Iterable, Optional, Sequence, TypeVar, Union from pytype import debug -from pytype import error_printer from pytype import pretty_printer from pytype import utils from pytype.abstract import abstract from pytype.abstract import function +from pytype.errors import error_printer from pytype.overlays import typed_dict as typed_dict_overlay from pytype.pytd import slots diff --git a/pytype/errors_test.py b/pytype/errors/errors_test.py similarity index 99% rename from pytype/errors_test.py rename to pytype/errors/errors_test.py index 90f6e812d..af3116702 100644 --- a/pytype/errors_test.py +++ b/pytype/errors/errors_test.py @@ -6,8 +6,8 @@ import textwrap from unittest import mock -from pytype import errors from pytype import state as frame_state +from pytype.errors import errors from pytype.platform_utils import path_utils from pytype.tests import test_utils @@ -291,8 +291,9 @@ def test_color_print_to_file(self): class ErrorDocTest(unittest.TestCase): + dirname = path_utils.dirname ERROR_FILE_PATH = path_utils.join( - path_utils.dirname(errors.__file__), "../docs/errors.md") + dirname(dirname(errors.__file__)), "../docs/errors.md") def _check_and_get_documented_errors(self): with open(self.ERROR_FILE_PATH) as f: diff --git a/pytype/rewrite/CMakeLists.txt b/pytype/rewrite/CMakeLists.txt index 2df1ecc6a..7bb34aa11 100644 --- a/pytype/rewrite/CMakeLists.txt +++ b/pytype/rewrite/CMakeLists.txt @@ -17,8 +17,8 @@ py_library( DEPS .vm pytype.config - pytype.errors pytype.load_pytd + pytype.errors.errors pytype.pytd.pytd ) diff --git a/pytype/rewrite/analyze.py b/pytype/rewrite/analyze.py index c395306cd..3483ad79d 100644 --- a/pytype/rewrite/analyze.py +++ b/pytype/rewrite/analyze.py @@ -5,8 +5,8 @@ from typing import Optional from pytype import config -from pytype import errors from pytype import load_pytd +from pytype.errors import errors from pytype.pytd import pytd from pytype.rewrite import vm as vm_lib diff --git a/pytype/tests/test_base_test.py b/pytype/tests/test_base_test.py index 63f8d3fb8..be7f3763a 100644 --- a/pytype/tests/test_base_test.py +++ b/pytype/tests/test_base_test.py @@ -2,7 +2,7 @@ import os -from pytype import errors +from pytype.errors import errors from pytype.tests import test_base from pytype.tests import test_utils