From cb0810e9438455a982277c72a18bf3d2bc81e084 Mon Sep 17 00:00:00 2001 From: knassre-bodo Date: Tue, 5 Nov 2024 16:51:48 -0500 Subject: [PATCH 1/3] Adding pyupgrade --- .../database_connectors/database_connector.py | 2 +- pydough/metadata/__init__.py | 12 +++--- pydough/metadata/abstract_metadata.py | 3 +- .../collections/collection_metadata.py | 24 ++++++------ .../collections/simple_table_metadata.py | 38 ++++++++++--------- pydough/metadata/errors.py | 8 ++-- pydough/metadata/graphs/graph_metadata.py | 4 +- pydough/metadata/parse.py | 24 ++++++------ pydough/metadata/properties/__init__.py | 10 ++--- .../properties/cartesian_product_metadata.py | 10 +++-- .../compound_relationship_metadata.py | 17 +++++---- .../properties/inherited_property_metadata.py | 5 ++- .../metadata/properties/property_metadata.py | 22 +++++------ .../reversible_property_metadata.py | 3 +- .../properties/scalar_attribute_metadata.py | 9 +++-- .../properties/simple_join_metadata.py | 20 +++++----- .../subcollection_relationship_metadata.py | 5 ++- .../properties/table_column_metadata.py | 21 ++++++---- pydough/pydough_ast/__init__.py | 18 ++++----- pydough/pydough_ast/collections/__init__.py | 10 ++--- .../collections/back_reference_collection.py | 10 +++-- pydough/pydough_ast/collections/calc.py | 9 +++-- .../collections/calc_child_collection.py | 6 +-- .../collections/collection_access.py | 13 ++++--- .../pydough_ast/collections/collection_ast.py | 10 ++--- .../collections/collection_tree_form.py | 9 +++-- .../collections/compound_sub_collection.py | 21 +++++----- .../pydough_ast/collections/global_context.py | 11 +++--- .../hidden_back_reference_collection.py | 4 +- .../pydough_ast/collections/sub_collection.py | 3 +- .../collections/table_collection.py | 3 +- pydough/pydough_ast/expressions/__init__.py | 8 ++-- .../expressions/back_reference_expression.py | 8 ++-- .../expressions/child_reference.py | 5 ++- .../expressions/column_property.py | 5 ++- .../pydough_ast/expressions/expression_ast.py | 1 - .../expressions/expression_function_call.py | 7 ++-- .../hidden_back_reference_expression.py | 1 + pydough/pydough_ast/expressions/literal.py | 3 +- pydough/pydough_ast/expressions/reference.py | 5 ++- pydough/pydough_ast/node_builder.py | 36 +++++++++--------- .../pydough_ast/pydough_operators/__init__.py | 28 +++++++------- .../expression_operators/__init__.py | 8 ++-- .../expression_operators/binary_operators.py | 7 ++-- .../expression_function_operators.py | 6 +-- .../expression_operator_ast.py | 6 +-- .../registered_expression_operators.py | 7 ++-- .../pydough_operators/operator_ast.py | 8 ++-- .../pydough_operators/operator_registry.py | 8 ++-- .../type_inference/__init__.py | 4 +- .../type_inference/expression_type_deducer.py | 3 +- .../type_inference/type_verifier.py | 6 +-- pydough/types/__init__.py | 18 ++++----- pydough/types/array_type.py | 10 ++--- pydough/types/binary_type.py | 4 +- pydough/types/boolean_type.py | 4 +- pydough/types/date_type.py | 4 +- pydough/types/decimal_type.py | 8 ++-- pydough/types/float_types.py | 6 +-- pydough/types/integer_types.py | 6 +-- pydough/types/map_type.py | 14 +++---- pydough/types/parse_types.py | 22 +++++------ pydough/types/string_type.py | 4 +- pydough/types/struct_type.py | 26 ++++++------- pydough/types/time_type.py | 10 ++--- pydough/types/timestamp_type.py | 23 +++++------ pydough/types/unknown_type.py | 4 +- pyproject.toml | 9 +++++ tests/conftest.py | 29 +++++++------- tests/test_ast_collection.py | 36 +++++++++--------- tests/test_ast_collection_errors.py | 14 ++++--- tests/test_ast_expression.py | 34 +++++++++-------- tests/test_ast_expression_errors.py | 15 ++++---- tests/test_expression_type_deducer.py | 9 +++-- tests/test_expression_type_deducer_errors.py | 14 ++++--- tests/test_metadata.py | 29 +++++++------- tests/test_metadata_errors.py | 7 ++-- tests/test_sqlite_connection.py | 4 +- tests/test_type_verifier.py | 9 +++-- tests/test_type_verifier_errors.py | 12 ++++-- tests/test_types.py | 4 +- tests/test_utils.py | 16 ++++---- tpch_demo/test_tpch_download.py | 2 +- 83 files changed, 506 insertions(+), 434 deletions(-) diff --git a/pydough/database_connectors/database_connector.py b/pydough/database_connectors/database_connector.py index bed3ec43..706c55ae 100644 --- a/pydough/database_connectors/database_connector.py +++ b/pydough/database_connectors/database_connector.py @@ -9,7 +9,7 @@ from typing import Any -class DatabaseConnection(object): +class DatabaseConnection: """ Class that manages a generic DB API 2.0 connection. This basically dispatches to the DB API 2.0 API on the underlying object and represents diff --git a/pydough/metadata/__init__.py b/pydough/metadata/__init__.py index c3c83d5f..aada5019 100644 --- a/pydough/metadata/__init__.py +++ b/pydough/metadata/__init__.py @@ -15,14 +15,14 @@ "SimpleTableMetadata", ] -from .parse import parse_json_metadata_from_file -from .graphs import GraphMetadata from .collections import CollectionMetadata, SimpleTableMetadata +from .errors import PyDoughMetadataException +from .graphs import GraphMetadata +from .parse import parse_json_metadata_from_file from .properties import ( - PropertyMetadata, - TableColumnMetadata, - SimpleJoinMetadata, CartesianProductMetadata, CompoundRelationshipMetadata, + PropertyMetadata, + SimpleJoinMetadata, + TableColumnMetadata, ) -from .errors import PyDoughMetadataException diff --git a/pydough/metadata/abstract_metadata.py b/pydough/metadata/abstract_metadata.py index b6952d7f..3a77e6c9 100644 --- a/pydough/metadata/abstract_metadata.py +++ b/pydough/metadata/abstract_metadata.py @@ -5,8 +5,7 @@ __all__ = ["AbstractMetadata"] from abc import ABC, abstractmethod - -from typing import MutableMapping, MutableSequence +from collections.abc import MutableMapping, MutableSequence class AbstractMetadata(ABC): diff --git a/pydough/metadata/collections/collection_metadata.py b/pydough/metadata/collections/collection_metadata.py index f190db60..8a8294b0 100644 --- a/pydough/metadata/collections/collection_metadata.py +++ b/pydough/metadata/collections/collection_metadata.py @@ -3,17 +3,17 @@ """ from abc import abstractmethod +from collections import defaultdict +from collections.abc import MutableMapping, MutableSequence -from typing import MutableSequence, MutableMapping, Set, Type +from pydough.metadata.abstract_metadata import AbstractMetadata from pydough.metadata.errors import ( + HasPropertyWith, + HasType, PyDoughMetadataException, - is_valid_name, is_string, - HasType, - HasPropertyWith, + is_valid_name, ) -from collections import defaultdict -from pydough.metadata.abstract_metadata import AbstractMetadata from pydough.metadata.graphs import GraphMetadata @@ -32,12 +32,12 @@ class CollectionMetadata(AbstractMetadata): # Set of names of of fields that can be included in the JSON # object describing a collection. Implementations should extend this. - allowed_fields: Set[str] = {"type", "properties"} + allowed_fields: set[str] = {"type", "properties"} def __init__(self, name: str, graph: GraphMetadata): from pydough.metadata.properties import ( - PropertyMetadata, InheritedPropertyMetadata, + PropertyMetadata, ) is_valid_name.verify(name, "name") @@ -194,8 +194,8 @@ def verify_allows_property( to insert into the collection. """ from pydough.metadata.properties import ( - PropertyMetadata, InheritedPropertyMetadata, + PropertyMetadata, ) # First, make sure that the candidate property is indeed a property @@ -323,7 +323,7 @@ def get_property(self, property_name: str) -> AbstractMetadata: @staticmethod def get_class_for_collection_type( name: str, error_name: str - ) -> Type["CollectionMetadata"]: + ) -> type["CollectionMetadata"]: """ Fetches the PropertyType implementation class for a string representation of the collection type. @@ -340,7 +340,7 @@ def get_class_for_collection_type( `PyDoughMetadataException` if the string does not correspond to a known class type. """ - from . import SimpleTableMetadata + from .simple_table_metadata import SimpleTableMetadata match name: case "simple_table": @@ -416,7 +416,7 @@ def parse_from_json( # Dispatch to a specific parsing procedure based on the type of # collection. - property_class: Type[CollectionMetadata] = ( + property_class: type[CollectionMetadata] = ( CollectionMetadata.get_class_for_collection_type( collection_json["type"], error_name ) diff --git a/pydough/metadata/collections/simple_table_metadata.py b/pydough/metadata/collections/simple_table_metadata.py index b758f010..868f9e7f 100644 --- a/pydough/metadata/collections/simple_table_metadata.py +++ b/pydough/metadata/collections/simple_table_metadata.py @@ -2,26 +2,28 @@ TODO: add file-level docstring """ -from typing import MutableSequence, Union, Set, Tuple +from collections.abc import MutableSequence + +from pydough.metadata.abstract_metadata import AbstractMetadata from pydough.metadata.errors import ( HasPropertyWith, - unique_properties_predicate, NoExtraKeys, - is_string, PyDoughMetadataException, + is_string, + unique_properties_predicate, ) -from pydough.metadata.abstract_metadata import AbstractMetadata from pydough.metadata.graphs import GraphMetadata -from . import CollectionMetadata from pydough.metadata.properties import ( - PropertyMetadata, - TableColumnMetadata, - SimpleJoinMetadata, - CompoundRelationshipMetadata, CartesianProductMetadata, + CompoundRelationshipMetadata, InheritedPropertyMetadata, + PropertyMetadata, + SimpleJoinMetadata, + TableColumnMetadata, ) +from .collection_metadata import CollectionMetadata + class SimpleTableMetadata(CollectionMetadata): """ @@ -32,7 +34,7 @@ class SimpleTableMetadata(CollectionMetadata): # Set of names of of fields that can be included in the JSON # object describing a simple table collection. - allowed_fields: Set[str] = CollectionMetadata.allowed_fields | { + allowed_fields: set[str] = CollectionMetadata.allowed_fields | { "table_path", "unique_properties", } @@ -42,7 +44,7 @@ def __init__( name: str, graph, table_path: str, - unique_properties: MutableSequence[Union[str, MutableSequence[str]]], + unique_properties: MutableSequence[str | MutableSequence[str]], ): super().__init__(name, graph) is_string.verify(table_path, f"Property 'table_path' of {self.error_name}") @@ -50,7 +52,7 @@ def __init__( unique_properties, f"property 'unique_properties' of {self.error_name}" ) self._table_path: str = table_path - self._unique_properties: MutableSequence[Union[str, MutableSequence[str]]] = ( + self._unique_properties: MutableSequence[str | MutableSequence[str]] = ( unique_properties ) @@ -63,7 +65,7 @@ def table_path(self) -> str: return self._table_path @property - def unique_properties(self) -> MutableSequence[Union[str, MutableSequence[str]]]: + def unique_properties(self) -> MutableSequence[str | MutableSequence[str]]: """ The list of all names of properties of the collection that are guaranteed to be unique within the collection. Entries that are a @@ -91,17 +93,17 @@ def verify_complete(self) -> None: # Extract all names properties used in the uniqueness of the table # collection, ensuring there are no invalid duplicates. malformed_unique_msg: str = f"{self.error_name} has malformed unique properties set: {self.unique_properties}" - unique_property_combinations: Set[Tuple] = set() - unique_property_names: Set[str] = set() + unique_property_combinations: set[tuple] = set() + unique_property_names: set[str] = set() for unique_property in self.unique_properties: - unique_property_set: Set[str] + unique_property_set: set[str] if isinstance(unique_property, str): unique_property_set = {unique_property} else: unique_property_set = set(unique_property) if len(unique_property_set) < len(unique_property): raise PyDoughMetadataException(malformed_unique_msg) - unique_property_tuple: Tuple = tuple(sorted(unique_property_set)) + unique_property_tuple: tuple = tuple(sorted(unique_property_set)) if unique_property_tuple in unique_property_combinations: raise PyDoughMetadataException(malformed_unique_msg) unique_property_combinations.add(unique_property_tuple) @@ -219,7 +221,7 @@ def parse_from_json( # Extract the relevant properties from the JSON to build the new # collection, then add it to the graph. table_path: str = collection_json["table_path"] - unique_properties: MutableSequence[Union[str, MutableSequence[str]]] = ( + unique_properties: MutableSequence[str | MutableSequence[str]] = ( collection_json["unique_properties"] ) new_collection: SimpleTableMetadata = SimpleTableMetadata( diff --git a/pydough/metadata/errors.py b/pydough/metadata/errors.py index 7e1d2218..4b9f716a 100644 --- a/pydough/metadata/errors.py +++ b/pydough/metadata/errors.py @@ -24,8 +24,8 @@ ] -from typing import MutableSequence, Set, Optional from abc import ABC, abstractmethod +from collections.abc import MutableSequence class PyDoughMetadataException(Exception): @@ -105,8 +105,8 @@ class NoExtraKeys(PyDoughPredicate): besides those that have been specified. """ - def __init__(self, valid_keys: Set[str]): - self.valid_keys: Set[str] = valid_keys + def __init__(self, valid_keys: set[str]): + self.valid_keys: set[str] = valid_keys def accept(self, obj: object) -> bool: return isinstance(obj, dict) and set(obj) <= self.valid_keys @@ -135,7 +135,7 @@ def error_message(self, error_name: str) -> str: class HasType(PyDoughPredicate): """Predicate class to check that an object has a certain type""" - def __init__(self, desired_type: type, type_name: Optional[str] = None): + def __init__(self, desired_type: type, type_name: str | None = None): self.desired_type: type = desired_type self.type_name: str = ( self.desired_type.__name__ if type_name is None else type_name diff --git a/pydough/metadata/graphs/graph_metadata.py b/pydough/metadata/graphs/graph_metadata.py index 08394cad..6c128968 100644 --- a/pydough/metadata/graphs/graph_metadata.py +++ b/pydough/metadata/graphs/graph_metadata.py @@ -2,11 +2,11 @@ TODO: add file-level docstring """ -from typing import MutableSequence, MutableMapping from collections import defaultdict -from pydough.metadata.errors import PyDoughMetadataException, is_valid_name, HasType +from collections.abc import MutableMapping, MutableSequence from pydough.metadata.abstract_metadata import AbstractMetadata +from pydough.metadata.errors import HasType, PyDoughMetadataException, is_valid_name class GraphMetadata(AbstractMetadata): diff --git a/pydough/metadata/parse.py b/pydough/metadata/parse.py index 6b6062e0..1a02de62 100644 --- a/pydough/metadata/parse.py +++ b/pydough/metadata/parse.py @@ -4,19 +4,19 @@ __all__ = ["parse_json_metadata_from_file"] -from typing import MutableMapping, MutableSequence, Tuple, Set, MutableSet -from .graphs import GraphMetadata +import json +from collections import deque +from collections.abc import MutableMapping, MutableSequence, MutableSet +from dataclasses import dataclass + +from .collections import CollectionMetadata from .errors import ( - PyDoughMetadataException, HasPropertyWith, HasType, + PyDoughMetadataException, ) -from collections import deque -from .collections import CollectionMetadata +from .graphs import GraphMetadata from .properties import PropertyMetadata -import json - -from dataclasses import dataclass # The way a property is stored until it is parsed. @@ -53,7 +53,7 @@ def parse_json_metadata_from_file(file_path: str, graph_name: str) -> GraphMetad `PyDoughMetadataException`: if the file is malformed in any way that prevents parsing it to obtain the desired graph. """ - with open(file_path, "r") as f: + with open(file_path) as f: as_json = json.load(f) if not isinstance(as_json, dict): raise PyDoughMetadataException( @@ -174,7 +174,7 @@ def topologically_sort_properties( # identifying `(collection_name, property_name)` tuple (hereafter # referred to as the `property`) and the values are a tuple of the # property's JSON and its index in the original raw_properties list. - reformatted_properties: MutableMapping[PropertyKey, Tuple[dict, int]] = { + reformatted_properties: MutableMapping[PropertyKey, tuple[dict, int]] = { PropertyKey(property.collection_name, property.property_name): ( property.property_json, i, @@ -204,7 +204,7 @@ def topologically_sort_properties( def get_property_dependencies( - reformatted_properties: MutableMapping[PropertyKey, Tuple[dict, int]], + reformatted_properties: MutableMapping[PropertyKey, tuple[dict, int]], ) -> MutableSequence[MutableSet[int]]: """ Infers the set of dependencies for each property. @@ -249,7 +249,7 @@ def get_property_dependencies( # A dictionary mapping each property to the set of all inherited property # names that are associated with it. - compound_inherited_aliases: MutableMapping[PropertyKey, Set[str]] = {} + compound_inherited_aliases: MutableMapping[PropertyKey, set[str]] = {} def get_true_property(property: PropertyKey) -> PropertyKey | None: """ diff --git a/pydough/metadata/properties/__init__.py b/pydough/metadata/properties/__init__.py index 30a8773b..775e75d3 100644 --- a/pydough/metadata/properties/__init__.py +++ b/pydough/metadata/properties/__init__.py @@ -14,12 +14,12 @@ "ScalarAttributeMetadata", ] -from .property_metadata import PropertyMetadata -from .reversible_property_metadata import ReversiblePropertyMetadata -from .table_column_metadata import TableColumnMetadata -from .simple_join_metadata import SimpleJoinMetadata from .cartesian_product_metadata import CartesianProductMetadata from .compound_relationship_metadata import CompoundRelationshipMetadata from .inherited_property_metadata import InheritedPropertyMetadata -from .subcollection_relationship_metadata import SubcollectionRelationshipMetadata +from .property_metadata import PropertyMetadata +from .reversible_property_metadata import ReversiblePropertyMetadata from .scalar_attribute_metadata import ScalarAttributeMetadata +from .simple_join_metadata import SimpleJoinMetadata +from .subcollection_relationship_metadata import SubcollectionRelationshipMetadata +from .table_column_metadata import TableColumnMetadata diff --git a/pydough/metadata/properties/cartesian_product_metadata.py b/pydough/metadata/properties/cartesian_product_metadata.py index 78ae1d03..51243c7b 100644 --- a/pydough/metadata/properties/cartesian_product_metadata.py +++ b/pydough/metadata/properties/cartesian_product_metadata.py @@ -4,10 +4,12 @@ __all__ = ["CartesianProductMetadata"] -from pydough.metadata.errors import HasPropertyWith, HasType, is_string, NoExtraKeys -from typing import Set + from pydough.metadata.collections import CollectionMetadata -from . import ReversiblePropertyMetadata, PropertyMetadata +from pydough.metadata.errors import HasPropertyWith, HasType, NoExtraKeys, is_string + +from .property_metadata import PropertyMetadata +from .reversible_property_metadata import ReversiblePropertyMetadata class CartesianProductMetadata(ReversiblePropertyMetadata): @@ -18,7 +20,7 @@ class CartesianProductMetadata(ReversiblePropertyMetadata): # Set of names of of fields that can be included in the JSON object # describing a cartesian product property. - allowed_fields: Set[str] = PropertyMetadata.allowed_fields | { + allowed_fields: set[str] = PropertyMetadata.allowed_fields | { "other_collection_name", "reverse_relationship_name", } diff --git a/pydough/metadata/properties/compound_relationship_metadata.py b/pydough/metadata/properties/compound_relationship_metadata.py index 539dbbb4..9693a9d1 100644 --- a/pydough/metadata/properties/compound_relationship_metadata.py +++ b/pydough/metadata/properties/compound_relationship_metadata.py @@ -4,20 +4,23 @@ __all__ = ["CompoundRelationshipMetadata"] -from typing import MutableMapping, Set, MutableSequence +from collections.abc import MutableMapping, MutableSequence + +from pydough.metadata.collections import CollectionMetadata from pydough.metadata.errors import ( HasPropertyWith, HasType, - is_string, NoExtraKeys, - compound_relationship_inherited_predicate, - PyDoughMetadataException, NonEmptyListOf, PossiblyEmptyMapOf, + PyDoughMetadataException, + compound_relationship_inherited_predicate, is_bool, + is_string, ) -from pydough.metadata.collections import CollectionMetadata -from . import PropertyMetadata, ReversiblePropertyMetadata + +from .property_metadata import PropertyMetadata +from .reversible_property_metadata import ReversiblePropertyMetadata class CompoundRelationshipMetadata(ReversiblePropertyMetadata): @@ -31,7 +34,7 @@ class CompoundRelationshipMetadata(ReversiblePropertyMetadata): # Set of names of of fields that can be included in the JSON object # describing a compound relationship property. - allowed_fields: Set[str] = PropertyMetadata.allowed_fields | { + allowed_fields: set[str] = PropertyMetadata.allowed_fields | { "primary_property", "secondary_property", "reverse_relationship_name", diff --git a/pydough/metadata/properties/inherited_property_metadata.py b/pydough/metadata/properties/inherited_property_metadata.py index 29607a2d..c8d8e6b7 100644 --- a/pydough/metadata/properties/inherited_property_metadata.py +++ b/pydough/metadata/properties/inherited_property_metadata.py @@ -4,11 +4,12 @@ __all__ = ["InheritedPropertyMetadata"] -from .property_metadata import PropertyMetadata -from .compound_relationship_metadata import CompoundRelationshipMetadata from pydough.metadata.collections import CollectionMetadata from pydough.metadata.errors import HasType, PyDoughMetadataException +from .compound_relationship_metadata import CompoundRelationshipMetadata +from .property_metadata import PropertyMetadata + class InheritedPropertyMetadata(PropertyMetadata): """ diff --git a/pydough/metadata/properties/property_metadata.py b/pydough/metadata/properties/property_metadata.py index d270032c..93a67c17 100644 --- a/pydough/metadata/properties/property_metadata.py +++ b/pydough/metadata/properties/property_metadata.py @@ -5,17 +5,17 @@ __all__ = ["PropertyMetadata"] from abc import abstractmethod +from collections.abc import MutableMapping, MutableSequence -from typing import MutableMapping, MutableSequence, Set, Type +from pydough.metadata.abstract_metadata import AbstractMetadata +from pydough.metadata.collections import CollectionMetadata from pydough.metadata.errors import ( HasPropertyWith, - is_valid_name, HasType, - is_string, PyDoughMetadataException, + is_string, + is_valid_name, ) -from pydough.metadata.abstract_metadata import AbstractMetadata -from pydough.metadata.collections import CollectionMetadata class PropertyMetadata(AbstractMetadata): @@ -34,7 +34,7 @@ class PropertyMetadata(AbstractMetadata): # Set of names of of fields that can be included in the JSON object # describing a property. Implementations should extend this. - allowed_fields: Set[str] = {"type"} + allowed_fields: set[str] = {"type"} def __init__(self, name: str, collection: CollectionMetadata): is_valid_name.verify(name, "name") @@ -108,7 +108,7 @@ def components(self) -> list: @staticmethod def get_class_for_property_type( name: str, error_name: str - ) -> Type["PropertyMetadata"]: + ) -> type["PropertyMetadata"]: """ Fetches the PropertyType implementation class for a string representation of the property type. @@ -126,10 +126,10 @@ def get_class_for_property_type( to a known property type. """ from pydough.metadata.properties import ( - TableColumnMetadata, - SimpleJoinMetadata, - CompoundRelationshipMetadata, CartesianProductMetadata, + CompoundRelationshipMetadata, + SimpleJoinMetadata, + TableColumnMetadata, ) match name: @@ -206,7 +206,7 @@ def parse_from_json( error_name = f"property {property_name!r} of {collection.error_name}" # Dispatch to each implementation's parseing method based on the type. - property_class: Type[PropertyMetadata] = ( + property_class: type[PropertyMetadata] = ( PropertyMetadata.get_class_for_property_type( property_json["type"], error_name ) diff --git a/pydough/metadata/properties/reversible_property_metadata.py b/pydough/metadata/properties/reversible_property_metadata.py index bc8c754f..e8f16180 100644 --- a/pydough/metadata/properties/reversible_property_metadata.py +++ b/pydough/metadata/properties/reversible_property_metadata.py @@ -6,10 +6,11 @@ from abc import abstractmethod -from .subcollection_relationship_metadata import SubcollectionRelationshipMetadata from pydough.metadata.collections import CollectionMetadata from pydough.metadata.errors import PyDoughMetadataException +from .subcollection_relationship_metadata import SubcollectionRelationshipMetadata + class ReversiblePropertyMetadata(SubcollectionRelationshipMetadata): """ diff --git a/pydough/metadata/properties/scalar_attribute_metadata.py b/pydough/metadata/properties/scalar_attribute_metadata.py index fb668ad5..65e6f89e 100644 --- a/pydough/metadata/properties/scalar_attribute_metadata.py +++ b/pydough/metadata/properties/scalar_attribute_metadata.py @@ -4,12 +4,13 @@ __all__ = ["ScalarAttributeMetadata"] -from pydough.types import PyDoughType -from pydough.metadata.errors import HasType +from abc import abstractmethod -from . import PropertyMetadata from pydough.metadata.collections import CollectionMetadata -from abc import abstractmethod +from pydough.metadata.errors import HasType +from pydough.types import PyDoughType + +from .property_metadata import PropertyMetadata class ScalarAttributeMetadata(PropertyMetadata): diff --git a/pydough/metadata/properties/simple_join_metadata.py b/pydough/metadata/properties/simple_join_metadata.py index 5c5b7efa..9b45bde4 100644 --- a/pydough/metadata/properties/simple_join_metadata.py +++ b/pydough/metadata/properties/simple_join_metadata.py @@ -4,20 +4,22 @@ __all__ = ["SimpleJoinMetadata"] -from . import PropertyMetadata -from .reversible_property_metadata import ReversiblePropertyMetadata -from typing import MutableSequence, MutableMapping, Tuple, Set +from collections.abc import MutableMapping, MutableSequence + from pydough.metadata.collections import CollectionMetadata from pydough.metadata.errors import ( - simple_join_keys_predicate, HasPropertyWith, HasType, - is_string, - is_bool, NoExtraKeys, PyDoughMetadataException, + is_bool, + is_string, + simple_join_keys_predicate, ) +from .property_metadata import PropertyMetadata +from .reversible_property_metadata import ReversiblePropertyMetadata + class SimpleJoinMetadata(ReversiblePropertyMetadata): """ @@ -27,7 +29,7 @@ class SimpleJoinMetadata(ReversiblePropertyMetadata): # Set of names of of fields that can be included in the JSON object # describing a simple join property. - allowed_fields: Set[str] = PropertyMetadata.allowed_fields | { + allowed_fields: set[str] = PropertyMetadata.allowed_fields | { "other_collection_name", "reverse_relationship_name", "singular", @@ -51,7 +53,7 @@ def __init__( simple_join_keys_predicate.verify(keys, self.error_name) self._keys: MutableMapping[str, MutableSequence[str]] = keys self._join_pairs: MutableSequence[ - Tuple[PropertyMetadata, PropertyMetadata] + tuple[PropertyMetadata, PropertyMetadata] ] = [] # Build the join pairs list by transforming the dictionary of property # names from keys into the actual properties of the source/target @@ -84,7 +86,7 @@ def keys(self) -> MutableMapping[str, MutableSequence[str]]: return self._keys @property - def join_pairs(self) -> MutableSequence[Tuple[PropertyMetadata, PropertyMetadata]]: + def join_pairs(self) -> MutableSequence[tuple[PropertyMetadata, PropertyMetadata]]: """ A list of pairs of properties from the current collection and other collection that must be equal to in order to identify matches. diff --git a/pydough/metadata/properties/subcollection_relationship_metadata.py b/pydough/metadata/properties/subcollection_relationship_metadata.py index 8865d9e9..b8b91f7b 100644 --- a/pydough/metadata/properties/subcollection_relationship_metadata.py +++ b/pydough/metadata/properties/subcollection_relationship_metadata.py @@ -6,9 +6,10 @@ from abc import abstractmethod -from .property_metadata import PropertyMetadata -from pydough.metadata.errors import HasType, is_bool from pydough.metadata.collections import CollectionMetadata +from pydough.metadata.errors import HasType, is_bool + +from .property_metadata import PropertyMetadata class SubcollectionRelationshipMetadata(PropertyMetadata): diff --git a/pydough/metadata/properties/table_column_metadata.py b/pydough/metadata/properties/table_column_metadata.py index 0e951549..4972ad91 100644 --- a/pydough/metadata/properties/table_column_metadata.py +++ b/pydough/metadata/properties/table_column_metadata.py @@ -4,14 +4,19 @@ __all__ = ["TableColumnMetadata"] -from typing import Set -from . import PropertyMetadata -from .scalar_attribute_metadata import ScalarAttributeMetadata -from pydough.types.errors import PyDoughTypeException -from pydough.metadata.errors import PyDoughMetadataException -from pydough.types import parse_type_from_string, PyDoughType + from pydough.metadata.collections import CollectionMetadata -from pydough.metadata.errors import HasPropertyWith, NoExtraKeys, is_string +from pydough.metadata.errors import ( + HasPropertyWith, + NoExtraKeys, + PyDoughMetadataException, + is_string, +) +from pydough.types import PyDoughType, parse_type_from_string +from pydough.types.errors import PyDoughTypeException + +from .property_metadata import PropertyMetadata +from .scalar_attribute_metadata import ScalarAttributeMetadata class TableColumnMetadata(ScalarAttributeMetadata): @@ -22,7 +27,7 @@ class TableColumnMetadata(ScalarAttributeMetadata): # Set of names of of fields that can be included in the JSON object # describing a table column property. - allowed_fields: Set[str] = PropertyMetadata.allowed_fields | { + allowed_fields: set[str] = PropertyMetadata.allowed_fields | { "data_type", "column_name", } diff --git a/pydough/pydough_ast/__init__.py b/pydough/pydough_ast/__init__.py index 6eda36e7..618d8cd4 100644 --- a/pydough/pydough_ast/__init__.py +++ b/pydough/pydough_ast/__init__.py @@ -18,18 +18,18 @@ ] from .abstract_pydough_ast import PyDoughAST +from .collections import ( + Calc, + CalcChildCollection, + PyDoughCollectionAST, + SubCollection, + TableCollection, +) from .errors import PyDoughASTException from .expressions import ( - PyDoughExpressionAST, ColumnProperty, - Literal, ExpressionFunctionCall, -) -from .collections import ( - PyDoughCollectionAST, - TableCollection, - SubCollection, - Calc, - CalcChildCollection, + Literal, + PyDoughExpressionAST, ) from .node_builder import AstNodeBuilder diff --git a/pydough/pydough_ast/collections/__init__.py b/pydough/pydough_ast/collections/__init__.py index 20b688ce..d803a527 100644 --- a/pydough/pydough_ast/collections/__init__.py +++ b/pydough/pydough_ast/collections/__init__.py @@ -13,11 +13,11 @@ "BackReferenceCollection", ] -from .collection_ast import PyDoughCollectionAST -from .table_collection import TableCollection -from .sub_collection import SubCollection +from .back_reference_collection import BackReferenceCollection from .calc import Calc from .calc_child_collection import CalcChildCollection -from .back_reference_collection import BackReferenceCollection -from .global_context import GlobalContext from .collection_access import CollectionAccess +from .collection_ast import PyDoughCollectionAST +from .global_context import GlobalContext +from .sub_collection import SubCollection +from .table_collection import TableCollection diff --git a/pydough/pydough_ast/collections/back_reference_collection.py b/pydough/pydough_ast/collections/back_reference_collection.py index 2171ba11..0dc56dd5 100644 --- a/pydough/pydough_ast/collections/back_reference_collection.py +++ b/pydough/pydough_ast/collections/back_reference_collection.py @@ -4,12 +4,14 @@ __all__ = ["BackReferenceCollection"] -from typing import MutableMapping, Tuple +from collections.abc import MutableMapping + from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST -from .collection_ast import PyDoughCollectionAST from pydough.pydough_ast.errors import PyDoughASTException -from .collection_tree_form import CollectionTreeForm + from .collection_access import CollectionAccess +from .collection_ast import PyDoughCollectionAST +from .collection_tree_form import CollectionTreeForm class BackReferenceCollection(CollectionAccess): @@ -65,7 +67,7 @@ def collection_access(self) -> CollectionAccess: return self._collection_access @property - def properties(self) -> MutableMapping[str, Tuple[int | None, PyDoughAST]]: + def properties(self) -> MutableMapping[str, tuple[int | None, PyDoughAST]]: return self.collection_access.properties def to_string(self) -> str: diff --git a/pydough/pydough_ast/collections/calc.py b/pydough/pydough_ast/collections/calc.py index 4574a3ae..2755935c 100644 --- a/pydough/pydough_ast/collections/calc.py +++ b/pydough/pydough_ast/collections/calc.py @@ -5,11 +5,12 @@ __all__ = ["Calc"] -from typing import MutableMapping, MutableSequence, Tuple, Set +from collections.abc import MutableMapping, MutableSequence from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.errors import PyDoughASTException from pydough.pydough_ast.expressions import PyDoughExpressionAST + from .collection_ast import PyDoughCollectionAST from .collection_tree_form import CollectionTreeForm @@ -31,7 +32,7 @@ def __init__( self._all_terms: MutableMapping[str, PyDoughAST] = {} def with_terms( - self, terms: MutableSequence[Tuple[str, PyDoughExpressionAST]] + self, terms: MutableSequence[tuple[str, PyDoughExpressionAST]] ) -> "Calc": """ Specifies the terms that are calculated inside of a CALC node, @@ -101,11 +102,11 @@ def preceding_context(self) -> PyDoughCollectionAST: return self._predecessor @property - def calc_terms(self) -> Set[str]: + def calc_terms(self) -> set[str]: return set(self.calc_term_indices) @property - def all_terms(self) -> Set[str]: + def all_terms(self) -> set[str]: if self._calc_term_indices is None: raise PyDoughASTException( "Cannot access `all_terms` of a Calc node before adding calc terms with `with_terms`" diff --git a/pydough/pydough_ast/collections/calc_child_collection.py b/pydough/pydough_ast/collections/calc_child_collection.py index bbade8aa..05c357b0 100644 --- a/pydough/pydough_ast/collections/calc_child_collection.py +++ b/pydough/pydough_ast/collections/calc_child_collection.py @@ -5,12 +5,12 @@ __all__ = ["CalcChildCollection"] -from .hidden_back_reference_collection import HiddenBackReferenceCollection from .back_reference_collection import BackReferenceCollection from .collection_access import CollectionAccess -from .table_collection import TableCollection from .collection_tree_form import CollectionTreeForm +from .hidden_back_reference_collection import HiddenBackReferenceCollection from .sub_collection import SubCollection +from .table_collection import TableCollection class CalcChildCollection(CollectionAccess): @@ -72,7 +72,7 @@ def to_tree_form(self) -> CollectionTreeForm: ) item_str: str if isinstance( - self.collection_access, (SubCollection, HiddenBackReferenceCollection) + self.collection_access, SubCollection | HiddenBackReferenceCollection ): item_str = f"SubCollection[{self.to_string()}]" elif isinstance(self.collection_access, BackReferenceCollection): diff --git a/pydough/pydough_ast/collections/collection_access.py b/pydough/pydough_ast/collections/collection_access.py index fecb2528..9921ffc1 100644 --- a/pydough/pydough_ast/collections/collection_access.py +++ b/pydough/pydough_ast/collections/collection_access.py @@ -5,18 +5,19 @@ __all__ = ["CollectionAccess"] -from typing import MutableMapping, MutableSequence, Tuple, Set +from collections.abc import MutableMapping, MutableSequence from pydough.metadata import ( CollectionMetadata, - PropertyMetadata, CompoundRelationshipMetadata, + PropertyMetadata, TableColumnMetadata, ) from pydough.metadata.properties import SubcollectionRelationshipMetadata from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.errors import PyDoughASTException from pydough.pydough_ast.expressions import ColumnProperty + from .collection_ast import PyDoughCollectionAST @@ -35,7 +36,7 @@ def __init__( self._collection: CollectionMetadata = collection self._ancestor: PyDoughCollectionAST = ancestor self._predecessor: PyDoughCollectionAST | None = predecessor - self._properties: MutableMapping[str, Tuple[int | None, PyDoughAST]] | None = ( + self._properties: MutableMapping[str, tuple[int | None, PyDoughAST]] | None = ( None ) @@ -52,7 +53,7 @@ def collection(self) -> CollectionMetadata: return self._collection @property - def properties(self) -> MutableMapping[str, Tuple[int | None, PyDoughAST]]: + def properties(self) -> MutableMapping[str, tuple[int | None, PyDoughAST]]: """ MutableMapping of each property of the table to a tuple (idx, property) where idx is the ordinal position of the property when included @@ -102,13 +103,13 @@ def preceding_context(self) -> PyDoughCollectionAST | None: return self._predecessor @property - def calc_terms(self) -> Set[str]: + def calc_terms(self) -> set[str]: # The calc terms are just all of the column properties (the ones # that have an index) return {name for name, (idx, _) in self.properties.items() if idx is not None} @property - def all_terms(self) -> Set[str]: + def all_terms(self) -> set[str]: return set(self.properties) def get_expression_position(self, expr_name: str) -> int: diff --git a/pydough/pydough_ast/collections/collection_ast.py b/pydough/pydough_ast/collections/collection_ast.py index 67f98fac..3a66a5dd 100644 --- a/pydough/pydough_ast/collections/collection_ast.py +++ b/pydough/pydough_ast/collections/collection_ast.py @@ -5,11 +5,11 @@ __all__ = ["PyDoughCollectionAST"] from abc import abstractmethod - -from typing import Set, Union +from typing import Union from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST -from pydough.pydough_ast.expressions import PyDoughExpressionAST +from pydough.pydough_ast.expressions.expression_ast import PyDoughExpressionAST + from .collection_tree_form import CollectionTreeForm @@ -42,7 +42,7 @@ def preceding_context(self) -> Union["PyDoughCollectionAST", None]: @property @abstractmethod - def calc_terms(self) -> Set[str]: + def calc_terms(self) -> set[str]: """ The list of expressions that would be retrieved if the collection were to have its results evaluated. This is the set of names in the @@ -51,7 +51,7 @@ def calc_terms(self) -> Set[str]: @property @abstractmethod - def all_terms(self) -> Set[str]: + def all_terms(self) -> set[str]: """ The set of expression/subcollection names accessible by the context. """ diff --git a/pydough/pydough_ast/collections/collection_tree_form.py b/pydough/pydough_ast/collections/collection_tree_form.py index 876435a0..e17a458c 100644 --- a/pydough/pydough_ast/collections/collection_tree_form.py +++ b/pydough/pydough_ast/collections/collection_tree_form.py @@ -5,10 +5,11 @@ __all__ = ["CollectionTreeForm"] -from typing import Union, MutableSequence +from collections.abc import MutableSequence +from typing import Union -class CollectionTreeForm(object): +class CollectionTreeForm: """ A class used for displaying PyDough collections in tree form. """ @@ -28,8 +29,8 @@ def __init__( self.has_predecessor = has_predecessor or (predecessor is not None) self.has_successor: bool = has_successor self.has_children: bool = has_children - self.predecessor: Union["CollectionTreeForm", None] = predecessor - self.nested_trees: MutableSequence["CollectionTreeForm"] = ( + self.predecessor: CollectionTreeForm | None = predecessor + self.nested_trees: MutableSequence[CollectionTreeForm] = ( [] if nested_trees is None else nested_trees ) diff --git a/pydough/pydough_ast/collections/compound_sub_collection.py b/pydough/pydough_ast/collections/compound_sub_collection.py index 95599900..027f5b07 100644 --- a/pydough/pydough_ast/collections/compound_sub_collection.py +++ b/pydough/pydough_ast/collections/compound_sub_collection.py @@ -5,19 +5,20 @@ __all__ = ["CompoundSubCollection"] -from typing import MutableMapping, MutableSequence, Tuple, Set +from collections.abc import MutableMapping, MutableSequence from pydough.metadata import CompoundRelationshipMetadata from pydough.metadata.properties import InheritedPropertyMetadata -from pydough.pydough_ast.errors import PyDoughASTException from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST -from .collection_ast import PyDoughCollectionAST -from .sub_collection import SubCollection -from .hidden_back_reference_collection import HiddenBackReferenceCollection +from pydough.pydough_ast.errors import PyDoughASTException from pydough.pydough_ast.expressions.hidden_back_reference_expression import ( HiddenBackReferenceExpression, ) +from .collection_ast import PyDoughCollectionAST +from .hidden_back_reference_collection import HiddenBackReferenceCollection +from .sub_collection import SubCollection + class CompoundSubCollection(SubCollection): """ @@ -32,7 +33,7 @@ def __init__( ): super().__init__(subcollection_property, ancestor) self._subcollection_chain: MutableSequence[SubCollection] = [] - self._inheritance_sources: MutableMapping[str, Tuple[int, str]] = {} + self._inheritance_sources: MutableMapping[str, tuple[int, str]] = {} def populate_subcollection_chain( self, @@ -84,7 +85,7 @@ def populate_subcollection_chain( term = source.get_term(property.name) assert isinstance(term, SubCollection) source = term - found_inherited: Set[str] = set() + found_inherited: set[str] = set() # Iterate through all the remaining inherited properties to # find any whose true name matches one of the properties of # the target collection. If so, they belong to the @@ -130,7 +131,7 @@ def subcollection_chain(self) -> MutableSequence[SubCollection]: return self._subcollection_chain @property - def inheritance_sources(self) -> MutableMapping[str, Tuple[int, str]]: + def inheritance_sources(self) -> MutableMapping[str, tuple[int, str]]: """ The mapping between each inherited property name and the integer position of the subcollection access it corresponds to from within @@ -143,7 +144,7 @@ def inheritance_sources(self) -> MutableMapping[str, Tuple[int, str]]: return self._inheritance_sources @property - def properties(self) -> MutableMapping[str, Tuple[int | None, PyDoughAST]]: + def properties(self) -> MutableMapping[str, tuple[int | None, PyDoughAST]]: # Lazily define the properties, if not already defined. if self._properties is None: # First invoke the TableCollection version to get the regular @@ -163,7 +164,7 @@ def properties(self) -> MutableMapping[str, Tuple[int | None, PyDoughAST]]: assert ancestor_context is not None self.populate_subcollection_chain(ancestor_context, compound, inherited_map) # Make sure none of the inherited terms went unaccounted for. - undefined_inherited: Set[str] = set(compound.inherited_properties) - set( + undefined_inherited: set[str] = set(compound.inherited_properties) - set( self.inheritance_sources ) if len(undefined_inherited) > 0: diff --git a/pydough/pydough_ast/collections/global_context.py b/pydough/pydough_ast/collections/global_context.py index 0ebb5a29..95505393 100644 --- a/pydough/pydough_ast/collections/global_context.py +++ b/pydough/pydough_ast/collections/global_context.py @@ -5,14 +5,15 @@ __all__ = ["TableCollection"] -from typing import MutableMapping, Set +from collections.abc import MutableMapping -from pydough.metadata import GraphMetadata, CollectionMetadata +from pydough.metadata import CollectionMetadata, GraphMetadata from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.errors import PyDoughASTException + from .collection_ast import PyDoughCollectionAST -from .table_collection import TableCollection from .collection_tree_form import CollectionTreeForm +from .table_collection import TableCollection class GlobalContext(PyDoughCollectionAST): @@ -52,12 +53,12 @@ def preceding_context(self) -> PyDoughCollectionAST | None: return None @property - def calc_terms(self) -> Set[str]: + def calc_terms(self) -> set[str]: # A global context does not have any calc terms return set() @property - def all_terms(self) -> Set[str]: + def all_terms(self) -> set[str]: return set(self.collections) def get_expression_position(self, expr_name: str) -> int: diff --git a/pydough/pydough_ast/collections/hidden_back_reference_collection.py b/pydough/pydough_ast/collections/hidden_back_reference_collection.py index 1ae75e50..dddb2243 100644 --- a/pydough/pydough_ast/collections/hidden_back_reference_collection.py +++ b/pydough/pydough_ast/collections/hidden_back_reference_collection.py @@ -5,10 +5,10 @@ __all__ = ["HiddenBackReferenceCollection"] -from .collection_ast import PyDoughCollectionAST from .back_reference_collection import BackReferenceCollection -from .collection_tree_form import CollectionTreeForm from .collection_access import CollectionAccess +from .collection_ast import PyDoughCollectionAST +from .collection_tree_form import CollectionTreeForm class HiddenBackReferenceCollection(BackReferenceCollection): diff --git a/pydough/pydough_ast/collections/sub_collection.py b/pydough/pydough_ast/collections/sub_collection.py index c473c16a..007e8161 100644 --- a/pydough/pydough_ast/collections/sub_collection.py +++ b/pydough/pydough_ast/collections/sub_collection.py @@ -6,9 +6,10 @@ from pydough.metadata.properties import SubcollectionRelationshipMetadata + +from .collection_access import CollectionAccess from .collection_ast import PyDoughCollectionAST from .collection_tree_form import CollectionTreeForm -from .collection_access import CollectionAccess class SubCollection(CollectionAccess): diff --git a/pydough/pydough_ast/collections/table_collection.py b/pydough/pydough_ast/collections/table_collection.py index 3dfc6620..259b436d 100644 --- a/pydough/pydough_ast/collections/table_collection.py +++ b/pydough/pydough_ast/collections/table_collection.py @@ -6,9 +6,10 @@ from pydough.metadata import CollectionMetadata + +from .collection_access import CollectionAccess from .collection_ast import PyDoughCollectionAST from .collection_tree_form import CollectionTreeForm -from .collection_access import CollectionAccess class TableCollection(CollectionAccess): diff --git a/pydough/pydough_ast/expressions/__init__.py b/pydough/pydough_ast/expressions/__init__.py index 35f7aef8..f79d4777 100644 --- a/pydough/pydough_ast/expressions/__init__.py +++ b/pydough/pydough_ast/expressions/__init__.py @@ -12,10 +12,10 @@ "ChildReference", ] -from .expression_ast import PyDoughExpressionAST +from .back_reference_expression import BackReferenceExpression +from .child_reference import ChildReference from .column_property import ColumnProperty -from .literal import Literal +from .expression_ast import PyDoughExpressionAST from .expression_function_call import ExpressionFunctionCall +from .literal import Literal from .reference import Reference -from .back_reference_expression import BackReferenceExpression -from .child_reference import ChildReference diff --git a/pydough/pydough_ast/expressions/back_reference_expression.py b/pydough/pydough_ast/expressions/back_reference_expression.py index fc800583..2734ac3c 100644 --- a/pydough/pydough_ast/expressions/back_reference_expression.py +++ b/pydough/pydough_ast/expressions/back_reference_expression.py @@ -3,11 +3,11 @@ """ __all__ = ["BackReferenceExpression"] - -from . import PyDoughExpressionAST -from pydough.types import PyDoughType -from pydough.pydough_ast.collections import PyDoughCollectionAST +from pydough.pydough_ast.collections.collection_ast import PyDoughCollectionAST from pydough.pydough_ast.errors import PyDoughASTException +from pydough.types import PyDoughType + +from .expression_ast import PyDoughExpressionAST from .reference import Reference diff --git a/pydough/pydough_ast/expressions/child_reference.py b/pydough/pydough_ast/expressions/child_reference.py index d5be3137..f766cd30 100644 --- a/pydough/pydough_ast/expressions/child_reference.py +++ b/pydough/pydough_ast/expressions/child_reference.py @@ -4,8 +4,9 @@ __all__ = ["ChildReference"] -from . import PyDoughExpressionAST -from pydough.pydough_ast.collections import PyDoughCollectionAST +from pydough.pydough_ast.collections.collection_ast import PyDoughCollectionAST + +from .expression_ast import PyDoughExpressionAST from .reference import Reference diff --git a/pydough/pydough_ast/expressions/column_property.py b/pydough/pydough_ast/expressions/column_property.py index b5c93dc9..ae4d11b6 100644 --- a/pydough/pydough_ast/expressions/column_property.py +++ b/pydough/pydough_ast/expressions/column_property.py @@ -4,10 +4,11 @@ __all__ = ["ColumnProperty"] +from pydough.metadata.properties import TableColumnMetadata from pydough.pydough_ast.errors import PyDoughASTException -from . import PyDoughExpressionAST from pydough.types import PyDoughType -from pydough.metadata.properties import TableColumnMetadata + +from .expression_ast import PyDoughExpressionAST class ColumnProperty(PyDoughExpressionAST): diff --git a/pydough/pydough_ast/expressions/expression_ast.py b/pydough/pydough_ast/expressions/expression_ast.py index 3d1bc5f1..4f964523 100644 --- a/pydough/pydough_ast/expressions/expression_ast.py +++ b/pydough/pydough_ast/expressions/expression_ast.py @@ -6,7 +6,6 @@ from abc import abstractmethod - from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.types import PyDoughType diff --git a/pydough/pydough_ast/expressions/expression_function_call.py b/pydough/pydough_ast/expressions/expression_function_call.py index e9360928..bd166be8 100644 --- a/pydough/pydough_ast/expressions/expression_function_call.py +++ b/pydough/pydough_ast/expressions/expression_function_call.py @@ -4,13 +4,14 @@ __all__ = ["ExpressionFunctionCall"] -from typing import MutableSequence, List +from collections.abc import MutableSequence from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.pydough_operators import PyDoughExpressionOperatorAST -from . import PyDoughExpressionAST from pydough.types import PyDoughType +from .expression_ast import PyDoughExpressionAST + class ExpressionFunctionCall(PyDoughExpressionAST): """ @@ -55,7 +56,7 @@ def requires_enclosing_parens(self, parent: PyDoughExpressionAST) -> bool: return self.operator.requires_enclosing_parens(parent) def to_string(self, tree_form: bool = False) -> str: - arg_strings: List[str] = [] + arg_strings: list[str] = [] for arg in self.args: arg_string: str if isinstance(arg, PyDoughExpressionAST): diff --git a/pydough/pydough_ast/expressions/hidden_back_reference_expression.py b/pydough/pydough_ast/expressions/hidden_back_reference_expression.py index 95610219..d823b6ad 100644 --- a/pydough/pydough_ast/expressions/hidden_back_reference_expression.py +++ b/pydough/pydough_ast/expressions/hidden_back_reference_expression.py @@ -5,6 +5,7 @@ __all__ = ["HiddenBackReferenceExpression"] from pydough.pydough_ast.collections import PyDoughCollectionAST + from .back_reference_expression import BackReferenceExpression diff --git a/pydough/pydough_ast/expressions/literal.py b/pydough/pydough_ast/expressions/literal.py index 904ceccc..91b033a9 100644 --- a/pydough/pydough_ast/expressions/literal.py +++ b/pydough/pydough_ast/expressions/literal.py @@ -4,9 +4,10 @@ __all__ = ["Literal"] -from .expression_ast import PyDoughExpressionAST from pydough.types import PyDoughType +from .expression_ast import PyDoughExpressionAST + class Literal(PyDoughExpressionAST): """ diff --git a/pydough/pydough_ast/expressions/reference.py b/pydough/pydough_ast/expressions/reference.py index 77c710a6..0b0321bc 100644 --- a/pydough/pydough_ast/expressions/reference.py +++ b/pydough/pydough_ast/expressions/reference.py @@ -4,9 +4,10 @@ __all__ = ["Reference"] -from . import PyDoughExpressionAST +from pydough.pydough_ast.collections.collection_ast import PyDoughCollectionAST from pydough.types import PyDoughType -from pydough.pydough_ast.collections import PyDoughCollectionAST + +from .expression_ast import PyDoughExpressionAST class Reference(PyDoughExpressionAST): diff --git a/pydough/pydough_ast/node_builder.py b/pydough/pydough_ast/node_builder.py index 003fcef3..93bab9e4 100644 --- a/pydough/pydough_ast/node_builder.py +++ b/pydough/pydough_ast/node_builder.py @@ -4,40 +4,42 @@ __all__ = ["AstNodeBuilder"] +from collections.abc import MutableMapping, MutableSequence + from pydough.metadata import ( - GraphMetadata, CollectionMetadata, + GraphMetadata, PropertyMetadata, - TableColumnMetadata, PyDoughMetadataException, + TableColumnMetadata, ) -from typing import MutableMapping, MutableSequence from pydough.types import PyDoughType + from .abstract_pydough_ast import PyDoughAST +from .collections import ( + BackReferenceCollection, + Calc, + CollectionAccess, + GlobalContext, + PyDoughCollectionAST, +) +from .errors import PyDoughASTException from .expressions import ( - Literal, - ExpressionFunctionCall, - ColumnProperty, - Reference, BackReferenceExpression, ChildReference, + ColumnProperty, + ExpressionFunctionCall, + Literal, + Reference, ) from .pydough_operators import ( + PyDoughExpressionOperatorAST, PyDoughOperatorAST, builtin_registered_operators, - PyDoughExpressionOperatorAST, -) -from .errors import PyDoughASTException -from .collections import ( - PyDoughCollectionAST, - Calc, - GlobalContext, - CollectionAccess, - BackReferenceCollection, ) -class AstNodeBuilder(object): +class AstNodeBuilder: """ Class used in testing to build AST nodes """ diff --git a/pydough/pydough_ast/pydough_operators/__init__.py b/pydough/pydough_ast/pydough_operators/__init__.py index b4045bad..c8e1b958 100644 --- a/pydough/pydough_ast/pydough_operators/__init__.py +++ b/pydough/pydough_ast/pydough_operators/__init__.py @@ -36,15 +36,6 @@ "BinaryOperator", ] -from .type_inference import ( - TypeVerifier, - AllowAny, - ExpressionTypeDeducer, - SelectArgumentType, - RequireNumArgs, - ConstantType, -) -from .operator_ast import PyDoughOperatorAST from .expression_operators import ( ADD, BAN, @@ -54,19 +45,28 @@ EQU, GEQ, GRT, + IFF, LEQ, LET, + LOWER, MOD, MUL, NEQ, POW, SUB, - LOWER, - IFF, SUM, - PyDoughExpressionOperatorAST, - ExpressionFunctionOperator, - BinOp, BinaryOperator, + BinOp, + ExpressionFunctionOperator, + PyDoughExpressionOperatorAST, ) +from .operator_ast import PyDoughOperatorAST from .operator_registry import builtin_registered_operators +from .type_inference import ( + AllowAny, + ConstantType, + ExpressionTypeDeducer, + RequireNumArgs, + SelectArgumentType, + TypeVerifier, +) diff --git a/pydough/pydough_ast/pydough_operators/expression_operators/__init__.py b/pydough/pydough_ast/pydough_operators/expression_operators/__init__.py index 92cc4588..5afea135 100644 --- a/pydough/pydough_ast/pydough_operators/expression_operators/__init__.py +++ b/pydough/pydough_ast/pydough_operators/expression_operators/__init__.py @@ -27,8 +27,9 @@ "SUM", ] +from .binary_operators import BinaryOperator, BinOp +from .expression_function_operators import ExpressionFunctionOperator from .expression_operator_ast import PyDoughExpressionOperatorAST -from .binary_operators import BinOp, BinaryOperator from .registered_expression_operators import ( ADD, BAN, @@ -38,15 +39,14 @@ EQU, GEQ, GRT, + IFF, LEQ, LET, + LOWER, MOD, MUL, NEQ, POW, SUB, - LOWER, - IFF, SUM, ) -from .expression_function_operators import ExpressionFunctionOperator diff --git a/pydough/pydough_ast/pydough_operators/expression_operators/binary_operators.py b/pydough/pydough_ast/pydough_operators/expression_operators/binary_operators.py index cde28760..d67463ce 100644 --- a/pydough/pydough_ast/pydough_operators/expression_operators/binary_operators.py +++ b/pydough/pydough_ast/pydough_operators/expression_operators/binary_operators.py @@ -4,16 +4,15 @@ __all__ = ["BinOp", "BinaryOperator"] -from typing import List +from enum import Enum from pydough.pydough_ast.expressions import PyDoughExpressionAST -from .expression_operator_ast import PyDoughExpressionOperatorAST from pydough.pydough_ast.pydough_operators.type_inference import ( ExpressionTypeDeducer, TypeVerifier, ) -from enum import Enum +from .expression_operator_ast import PyDoughExpressionOperatorAST class BinOp(Enum): @@ -75,7 +74,7 @@ def requires_enclosing_parens(self, parent: PyDoughExpressionAST) -> bool: parent.operator, BinaryOperator ) - def to_string(self, arg_strings: List[str]) -> str: + def to_string(self, arg_strings: list[str]) -> str: # Stringify as "? + ?" for 0 arguments, "a + ?" for 1 argument, and # "a + b + ..." for 2+ arguments if len(arg_strings) < 2: diff --git a/pydough/pydough_ast/pydough_operators/expression_operators/expression_function_operators.py b/pydough/pydough_ast/pydough_operators/expression_operators/expression_function_operators.py index dab2cd99..bd6bfaaf 100644 --- a/pydough/pydough_ast/pydough_operators/expression_operators/expression_function_operators.py +++ b/pydough/pydough_ast/pydough_operators/expression_operators/expression_function_operators.py @@ -4,15 +4,15 @@ __all__ = ["ExpressionFunctionOperator"] -from typing import List from pydough.pydough_ast.expressions import PyDoughExpressionAST -from .expression_operator_ast import PyDoughExpressionOperatorAST from pydough.pydough_ast.pydough_operators.type_inference import ( ExpressionTypeDeducer, TypeVerifier, ) +from .expression_operator_ast import PyDoughExpressionOperatorAST + class ExpressionFunctionOperator(PyDoughExpressionOperatorAST): """ @@ -49,7 +49,7 @@ def standalone_string(self) -> str: def requires_enclosing_parens(self, parent: PyDoughExpressionAST) -> bool: return False - def to_string(self, arg_strings: List[str]) -> str: + def to_string(self, arg_strings: list[str]) -> str: # Stringify as "function_name(arg0, arg1, ...) return f"{self.function_name}({', '.join(arg_strings)})" diff --git a/pydough/pydough_ast/pydough_operators/expression_operators/expression_operator_ast.py b/pydough/pydough_ast/pydough_operators/expression_operators/expression_operator_ast.py index ec68f4ce..d829fa74 100644 --- a/pydough/pydough_ast/pydough_operators/expression_operators/expression_operator_ast.py +++ b/pydough/pydough_ast/pydough_operators/expression_operators/expression_operator_ast.py @@ -4,17 +4,17 @@ __all__ = ["PyDoughExpressionOperatorAST"] -from typing import MutableSequence from abc import abstractmethod +from collections.abc import MutableSequence -from pydough.pydough_ast.pydough_operators import PyDoughOperatorAST -from pydough.types import PyDoughType from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.expressions import PyDoughExpressionAST +from pydough.pydough_ast.pydough_operators.operator_ast import PyDoughOperatorAST from pydough.pydough_ast.pydough_operators.type_inference import ( ExpressionTypeDeducer, TypeVerifier, ) +from pydough.types import PyDoughType class PyDoughExpressionOperatorAST(PyDoughOperatorAST): diff --git a/pydough/pydough_ast/pydough_operators/expression_operators/registered_expression_operators.py b/pydough/pydough_ast/pydough_operators/expression_operators/registered_expression_operators.py index eefaff48..c534cc2b 100644 --- a/pydough/pydough_ast/pydough_operators/expression_operators/registered_expression_operators.py +++ b/pydough/pydough_ast/pydough_operators/expression_operators/registered_expression_operators.py @@ -23,15 +23,16 @@ "SUM", ] -from .binary_operators import BinaryOperator, BinOp -from .expression_function_operators import ExpressionFunctionOperator from pydough.pydough_ast.pydough_operators.type_inference import ( + ConstantType, RequireNumArgs, SelectArgumentType, - ConstantType, ) from pydough.types import BooleanType +from .binary_operators import BinaryOperator, BinOp +from .expression_function_operators import ExpressionFunctionOperator + # TODO: replace with full argument verifiers & deducers ADD = BinaryOperator(BinOp.ADD, RequireNumArgs(2), SelectArgumentType(0)) SUB = BinaryOperator(BinOp.SUB, RequireNumArgs(2), SelectArgumentType(0)) diff --git a/pydough/pydough_ast/pydough_operators/operator_ast.py b/pydough/pydough_ast/pydough_operators/operator_ast.py index 403a049b..054df9e4 100644 --- a/pydough/pydough_ast/pydough_operators/operator_ast.py +++ b/pydough/pydough_ast/pydough_operators/operator_ast.py @@ -5,11 +5,11 @@ __all__ = ["PyDoughOperatorAST"] from abc import abstractmethod - -from typing import List, MutableSequence +from collections.abc import MutableSequence from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.errors import PyDoughASTException + from .type_inference import TypeVerifier @@ -64,12 +64,12 @@ def verify_allows_args(self, args: MutableSequence[PyDoughAST]) -> None: # If the verifier failed, raise the error with the same traceback # but prepend it with information about the operator and args # that caused the failure. - arg_strings: List[str] = [str(arg) for arg in args] + arg_strings: list[str] = [str(arg) for arg in args] msg = f"Invalid operator invocation {self.to_string(arg_strings)!r}: {e}" raise PyDoughASTException(msg).with_traceback(e.__traceback__) @abstractmethod - def to_string(self, arg_strings: List[str]) -> str: + def to_string(self, arg_strings: list[str]) -> str: """ Returns the string representation of the operator when called on its arguments, which have already been converted to a string. diff --git a/pydough/pydough_ast/pydough_operators/operator_registry.py b/pydough/pydough_ast/pydough_operators/operator_registry.py index 9dd4b982..2609aafd 100644 --- a/pydough/pydough_ast/pydough_operators/operator_registry.py +++ b/pydough/pydough_ast/pydough_operators/operator_registry.py @@ -4,10 +4,12 @@ __all__ = ["builtin_registered_operators"] -from .operator_ast import PyDoughOperatorAST -from typing import MutableMapping -import pydough.pydough_ast.pydough_operators.expression_operators.registered_expression_operators as REP import inspect +from collections.abc import MutableMapping + +import pydough.pydough_ast.pydough_operators.expression_operators.registered_expression_operators as REP + +from .operator_ast import PyDoughOperatorAST def builtin_registered_operators() -> MutableMapping[str, PyDoughOperatorAST]: diff --git a/pydough/pydough_ast/pydough_operators/type_inference/__init__.py b/pydough/pydough_ast/pydough_operators/type_inference/__init__.py index 940aab6b..22fd872c 100644 --- a/pydough/pydough_ast/pydough_operators/type_inference/__init__.py +++ b/pydough/pydough_ast/pydough_operators/type_inference/__init__.py @@ -11,9 +11,9 @@ "RequireNumArgs", ] -from .type_verifier import TypeVerifier, AllowAny, RequireNumArgs from .expression_type_deducer import ( + ConstantType, ExpressionTypeDeducer, SelectArgumentType, - ConstantType, ) +from .type_verifier import AllowAny, RequireNumArgs, TypeVerifier diff --git a/pydough/pydough_ast/pydough_operators/type_inference/expression_type_deducer.py b/pydough/pydough_ast/pydough_operators/type_inference/expression_type_deducer.py index 76c81cae..52220602 100644 --- a/pydough/pydough_ast/pydough_operators/type_inference/expression_type_deducer.py +++ b/pydough/pydough_ast/pydough_operators/type_inference/expression_type_deducer.py @@ -5,8 +5,7 @@ __all__ = ["ExpressionTypeDeducer", "ConstantType", "SelectArgumentType"] from abc import ABC, abstractmethod - -from typing import MutableSequence +from collections.abc import MutableSequence from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST from pydough.pydough_ast.errors import PyDoughASTException diff --git a/pydough/pydough_ast/pydough_operators/type_inference/type_verifier.py b/pydough/pydough_ast/pydough_operators/type_inference/type_verifier.py index 4ad19a47..6ad75847 100644 --- a/pydough/pydough_ast/pydough_operators/type_inference/type_verifier.py +++ b/pydough/pydough_ast/pydough_operators/type_inference/type_verifier.py @@ -5,10 +5,10 @@ __all__ = ["TypeVerifier", "RequireNumArgs", "AllowAny"] from abc import ABC, abstractmethod +from collections.abc import MutableSequence -from typing import MutableSequence - -from pydough.pydough_ast import PyDoughAST, PyDoughASTException +from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST +from pydough.pydough_ast.errors import PyDoughASTException class TypeVerifier(ABC): diff --git a/pydough/types/__init__.py b/pydough/types/__init__.py index 68f5fd2d..7848b39e 100644 --- a/pydough/types/__init__.py +++ b/pydough/types/__init__.py @@ -24,18 +24,18 @@ "parse_type_from_string", ] -from .pydough_type import PyDoughType -from .integer_types import Int8Type, Int16Type, Int32Type, Int64Type -from .float_types import Float32Type, Float64Type +from .array_type import ArrayType +from .binary_type import BinaryType from .boolean_type import BooleanType +from .date_type import DateType from .decimal_type import DecimalType +from .float_types import Float32Type, Float64Type +from .integer_types import Int8Type, Int16Type, Int32Type, Int64Type +from .map_type import MapType +from .parse_types import parse_type_from_string +from .pydough_type import PyDoughType from .string_type import StringType -from .binary_type import BinaryType -from .date_type import DateType +from .struct_type import StructType from .time_type import TimeType from .timestamp_type import TimestampType -from .array_type import ArrayType -from .map_type import MapType -from .struct_type import StructType from .unknown_type import UnknownType -from .parse_types import parse_type_from_string diff --git a/pydough/types/array_type.py b/pydough/types/array_type.py index bfe3051d..f108fb18 100644 --- a/pydough/types/array_type.py +++ b/pydough/types/array_type.py @@ -4,10 +4,10 @@ __all__ = ["ArrayType"] -from .pydough_type import PyDoughType -from .errors import PyDoughTypeException import re -from typing import Optional + +from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class ArrayType(PyDoughType): @@ -40,12 +40,12 @@ def json_string(self) -> str: type_string_pattern: re.Pattern = re.compile(r"array\[(.+)\]") @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: from pydough.types import parse_type_from_string # Verify that the string matches the array type regex pattern, extracting # the element type string. - match: Optional[re.Match] = ArrayType.type_string_pattern.fullmatch(type_string) + match: re.Match | None = ArrayType.type_string_pattern.fullmatch(type_string) if match is None: return None diff --git a/pydough/types/binary_type.py b/pydough/types/binary_type.py index 02b628f9..8a2842f1 100644 --- a/pydough/types/binary_type.py +++ b/pydough/types/binary_type.py @@ -4,8 +4,8 @@ __all__ = ["BinaryType"] + from .pydough_type import PyDoughType -from typing import Optional class BinaryType(PyDoughType): @@ -24,5 +24,5 @@ def json_string(self) -> str: return "binary" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: return BinaryType() if type_string == "binary" else None diff --git a/pydough/types/boolean_type.py b/pydough/types/boolean_type.py index 63fcfa24..06d12639 100644 --- a/pydough/types/boolean_type.py +++ b/pydough/types/boolean_type.py @@ -4,8 +4,8 @@ __all__ = ["BooleanType"] + from .pydough_type import PyDoughType -from typing import Optional class BooleanType(PyDoughType): @@ -24,5 +24,5 @@ def json_string(self) -> str: return "bool" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: return BooleanType() if type_string == "bool" else None diff --git a/pydough/types/date_type.py b/pydough/types/date_type.py index c67d5b58..6a37e1db 100644 --- a/pydough/types/date_type.py +++ b/pydough/types/date_type.py @@ -4,8 +4,8 @@ __all__ = ["DateType"] + from .pydough_type import PyDoughType -from typing import Optional class DateType(PyDoughType): @@ -24,5 +24,5 @@ def json_string(self) -> str: return "date" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: return DateType() if type_string == "date" else None diff --git a/pydough/types/decimal_type.py b/pydough/types/decimal_type.py index 5aca2b05..05b74d47 100644 --- a/pydough/types/decimal_type.py +++ b/pydough/types/decimal_type.py @@ -4,10 +4,10 @@ __all__ = ["DecimalType"] -from .pydough_type import PyDoughType -from .errors import PyDoughTypeException import re -from typing import Optional + +from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class DecimalType(PyDoughType): @@ -55,7 +55,7 @@ def json_string(self) -> str: type_string_pattern: re.Pattern = re.compile(r"decimal\[(\d{1,2}),(\d{1,2})\]") @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: # Verify that the string matches the time type regex pattern, and # extract the precision and scale. match = DecimalType.type_string_pattern.fullmatch(type_string) diff --git a/pydough/types/float_types.py b/pydough/types/float_types.py index 0e610c6b..d81450a5 100644 --- a/pydough/types/float_types.py +++ b/pydough/types/float_types.py @@ -4,9 +4,9 @@ __all__ = ["FloatType"] -from .pydough_type import PyDoughType + from .errors import PyDoughTypeException -from typing import Optional +from .pydough_type import PyDoughType class FloatType(PyDoughType): @@ -33,7 +33,7 @@ def json_string(self) -> str: return f"float{self.bit_width}" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: match type_string: case "float32": return Float32Type() diff --git a/pydough/types/integer_types.py b/pydough/types/integer_types.py index 4f49e877..76640862 100644 --- a/pydough/types/integer_types.py +++ b/pydough/types/integer_types.py @@ -4,9 +4,9 @@ __all__ = ["IntegerType", "Int8Type", "Int16Type", "Int32Type", "Int64Type"] -from .pydough_type import PyDoughType -from typing import Optional + from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class IntegerType(PyDoughType): @@ -33,7 +33,7 @@ def json_string(self) -> str: return f"int{self.bit_width}" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: match type_string: case "int8": return Int8Type() diff --git a/pydough/types/map_type.py b/pydough/types/map_type.py index 7f2ef16a..80df853d 100644 --- a/pydough/types/map_type.py +++ b/pydough/types/map_type.py @@ -4,10 +4,10 @@ __all__ = ["MapType"] -from .pydough_type import PyDoughType -from .errors import PyDoughTypeException import re -from typing import Optional + +from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class MapType(PyDoughType): @@ -53,12 +53,12 @@ def json_string(self) -> str: type_string_pattern: re.Pattern = re.compile(r"map\[(.+,.+)\]") @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: from pydough.types import parse_type_from_string # Verify that the string matches the map type regex pattern, extracting # the body string. - match: Optional[re.Match] = MapType.type_string_pattern.fullmatch(type_string) + match: re.Match | None = MapType.type_string_pattern.fullmatch(type_string) if match is None: return None map_body: str = str(match.groups(0)[0]) @@ -67,8 +67,8 @@ def parse_from_string(type_string: str) -> Optional[PyDoughType]: # key,value in the body. Identify which one is valid by attempting # to parse both sides of the comma as a type. Whichever split succeeds # is the correct split. - key_type: Optional[PyDoughType] = None - val_type: Optional[PyDoughType] = None + key_type: PyDoughType | None = None + val_type: PyDoughType | None = None for i in range(len(map_body)): if map_body[i] == ",": try: diff --git a/pydough/types/parse_types.py b/pydough/types/parse_types.py index c5617b8b..5f982991 100644 --- a/pydough/types/parse_types.py +++ b/pydough/types/parse_types.py @@ -4,30 +4,30 @@ __all__ = ["parse_type_from_string"] -from typing import Type, MutableSequence +from collections.abc import MutableSequence -from .pydough_type import PyDoughType -from .integer_types import Int8Type, Int16Type, Int32Type, Int64Type -from .float_types import Float32Type, Float64Type +from .array_type import ArrayType +from .binary_type import BinaryType from .boolean_type import BooleanType +from .date_type import DateType from .decimal_type import DecimalType +from .errors import PyDoughTypeException +from .float_types import Float32Type, Float64Type +from .integer_types import Int8Type, Int16Type, Int32Type, Int64Type +from .map_type import MapType +from .pydough_type import PyDoughType from .string_type import StringType -from .binary_type import BinaryType -from .date_type import DateType +from .struct_type import StructType from .time_type import TimeType from .timestamp_type import TimestampType -from .array_type import ArrayType -from .map_type import MapType -from .struct_type import StructType from .unknown_type import UnknownType -from .errors import PyDoughTypeException def parse_type_from_string(type_string: str) -> PyDoughType: """ TODO: add function docstring """ - type_classes: MutableSequence[Type[PyDoughType]] = [ + type_classes: MutableSequence[type[PyDoughType]] = [ BinaryType, BooleanType, DecimalType, diff --git a/pydough/types/string_type.py b/pydough/types/string_type.py index a196e069..2e769535 100644 --- a/pydough/types/string_type.py +++ b/pydough/types/string_type.py @@ -4,8 +4,8 @@ __all__ = ["StringType"] + from .pydough_type import PyDoughType -from typing import Optional class StringType(PyDoughType): @@ -24,5 +24,5 @@ def json_string(self) -> str: return "string" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: return StringType() if type_string == "string" else None diff --git a/pydough/types/struct_type.py b/pydough/types/struct_type.py index ad03726c..ea8d4027 100644 --- a/pydough/types/struct_type.py +++ b/pydough/types/struct_type.py @@ -4,11 +4,11 @@ __all__ = ["StructType"] -from typing import MutableSequence, Tuple -from .pydough_type import PyDoughType -from .errors import PyDoughTypeException import re -from typing import Optional +from collections.abc import MutableSequence + +from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class StructType(PyDoughType): @@ -16,7 +16,7 @@ class StructType(PyDoughType): The PyDough type representing a collection of named fields. """ - def __init__(self, fields: MutableSequence[Tuple[str, PyDoughType]]): + def __init__(self, fields: MutableSequence[tuple[str, PyDoughType]]): if not ( isinstance(fields, list) and len(fields) > 0 @@ -31,10 +31,10 @@ def __init__(self, fields: MutableSequence[Tuple[str, PyDoughType]]): raise PyDoughTypeException( f"Invalid fields type for StructType: {fields!r}" ) - self._fields: MutableSequence[Tuple[str, PyDoughType]] = fields + self._fields: MutableSequence[tuple[str, PyDoughType]] = fields @property - def fields(self) -> MutableSequence[Tuple[str, PyDoughType]]: + def fields(self) -> MutableSequence[tuple[str, PyDoughType]]: """ The list of fields of the struct in the form (field_name, field_type). """ @@ -53,7 +53,7 @@ def json_string(self) -> str: type_string_pattern: re.Pattern = re.compile(r"struct\[(.+:.+)\]") @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: # Verify that the string matches the struct type regex pattern, extracting # the body string. match = StructType.type_string_pattern.fullmatch(type_string) @@ -62,7 +62,7 @@ def parse_from_string(type_string: str) -> Optional[PyDoughType]: # Extract the list of fields from the body string. If the attempt fails, # then the parsing fails. - fields: MutableSequence[Tuple[str, PyDoughType]] | None = ( + fields: MutableSequence[tuple[str, PyDoughType]] | None = ( StructType.parse_struct_body(str(match.groups(0)[0])) ) if fields is None or len(fields) == 0: @@ -72,7 +72,7 @@ def parse_from_string(type_string: str) -> Optional[PyDoughType]: @staticmethod def parse_struct_body( struct_body_string: str, - ) -> Optional[MutableSequence[Tuple[str, PyDoughType]]]: + ) -> MutableSequence[tuple[str, PyDoughType]] | None: """ Attempts to parse and extract a list of (field_name, field_type) tuples from a string which can contain 1 or more fields in the form @@ -83,7 +83,7 @@ def parse_struct_body( from pydough.types import parse_type_from_string # Keep track of all fields extracted so far. - fields: MutableSequence[Tuple[str, PyDoughType]] = [] + fields: MutableSequence[tuple[str, PyDoughType]] = [] # Iterate across the string to identify all colons that are candidate # splitting locations, where the left hand side is the name of a field @@ -100,8 +100,8 @@ def parse_struct_body( # Special case: if the entire right hand side string is a # PyDough type, then the parsing has succeed in finding a # single (field_name, field_type) pair from the entire string. - field_type: Optional[PyDoughType] = None - suffix_fields: Optional[MutableSequence[Tuple[str, PyDoughType]]] = None + field_type: PyDoughType | None = None + suffix_fields: MutableSequence[tuple[str, PyDoughType]] | None = None try: field_type = parse_type_from_string(struct_body_string[i + 1 :]) fields.append((field_name, field_type)) diff --git a/pydough/types/time_type.py b/pydough/types/time_type.py index 6de282af..1c7ffd7e 100644 --- a/pydough/types/time_type.py +++ b/pydough/types/time_type.py @@ -4,10 +4,10 @@ __all__ = ["TimeType"] -from .pydough_type import PyDoughType -from .errors import PyDoughTypeException import re -from typing import Optional + +from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class TimeType(PyDoughType): @@ -40,10 +40,10 @@ def json_string(self) -> str: type_string_pattern: re.Pattern = re.compile(r"time\[(\d)\]") @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: # Verify that the string matches the time type regex pattern, and # extract the precision. - match: Optional[re.Match] = TimeType.type_string_pattern.fullmatch(type_string) + match: re.Match | None = TimeType.type_string_pattern.fullmatch(type_string) if match is None: return None precision: int = int(match.groups(0)[0]) diff --git a/pydough/types/timestamp_type.py b/pydough/types/timestamp_type.py index 390492b2..6e06a38d 100644 --- a/pydough/types/timestamp_type.py +++ b/pydough/types/timestamp_type.py @@ -4,11 +4,12 @@ __all__ = ["TimestampType"] -from .pydough_type import PyDoughType -from .errors import PyDoughTypeException -import pytz import re -from typing import Optional + +import pytz + +from .errors import PyDoughTypeException +from .pydough_type import PyDoughType class TimestampType(PyDoughType): @@ -16,7 +17,7 @@ class TimestampType(PyDoughType): The PyDough type for timestamps with a precision and (optional) time zone. """ - def __init__(self, precision: int, tz: Optional[str] = None): + def __init__(self, precision: int, tz: str | None = None): if not isinstance(precision, int) or precision not in range(10): raise PyDoughTypeException( f"Invalid precision for TimestampType: {precision!r}" @@ -24,7 +25,7 @@ def __init__(self, precision: int, tz: Optional[str] = None): if not (tz is None or (isinstance(tz, str) and tz in pytz.all_timezones_set)): raise PyDoughTypeException(f"Invalid timezone for TimestampType: {tz!r}") self._precision: int = precision - self._tz: Optional[str] = tz + self._tz: str | None = tz @property def precision(self) -> int: @@ -36,7 +37,7 @@ def precision(self) -> int: return self._precision @property - def tz(self) -> Optional[str]: + def tz(self) -> str | None: """ The timezone of the timestamp type, if one exists. """ @@ -58,16 +59,16 @@ def json_string(self) -> str: type_string_pattern_with_tz: re.Pattern = re.compile(r"timestamp\[(\d),(.*)\]") @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: # Verify that the string matches one of the timestamp type regex # patterns, extracting the precision and timezone (if present). - match_no_tz: Optional[re.Match] = ( + match_no_tz: re.Match | None = ( TimestampType.type_string_pattern_no_tz.fullmatch(type_string) ) - match_with_tz: Optional[re.Match] = ( + match_with_tz: re.Match | None = ( TimestampType.type_string_pattern_with_tz.fullmatch(type_string) ) - tz: Optional[str] = None + tz: str | None = None precision: int if match_no_tz is not None: precision = int(match_no_tz.groups(0)[0]) diff --git a/pydough/types/unknown_type.py b/pydough/types/unknown_type.py index 049ab4d7..471c16cf 100644 --- a/pydough/types/unknown_type.py +++ b/pydough/types/unknown_type.py @@ -4,8 +4,8 @@ __all__ = ["UnknownType"] + from .pydough_type import PyDoughType -from typing import Optional class UnknownType(PyDoughType): @@ -24,5 +24,5 @@ def json_string(self) -> str: return "unknown" @staticmethod - def parse_from_string(type_string: str) -> Optional[PyDoughType]: + def parse_from_string(type_string: str) -> PyDoughType | None: return UnknownType() if type_string == "unknown" else None diff --git a/pyproject.toml b/pyproject.toml index 43a0a39e..70917b6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,3 +14,12 @@ dev-dependencies = ["pre-commit", "pytest", "ruff==0.6.7"] [build-system] requires = ["hatchling"] build-backend = "hatchling.build" + +[tool.ruff] +unsafe-fixes = true +lint.extend-select = [ + "I", # isort + "UP", # pyupgrade + "C4", # flake8-comprehensions + "TID", # flake8-tidy-imports +] \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 4605604c..a6df7951 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,18 +2,19 @@ TODO: add file-level docstring. """ -import pydough -import pytest import json -from pydough.metadata.graphs import GraphMetadata -from typing import MutableMapping, Set -from pydough.pydough_ast import AstNodeBuilder, pydough_operators as pydop - -from test_utils import graph_fetcher, noun_fetcher, map_over_dict_values - import os import sqlite3 +from collections.abc import MutableMapping + +import pytest +from test_utils import graph_fetcher, map_over_dict_values, noun_fetcher + +import pydough from pydough.database_connectors.database_connector import DatabaseConnection +from pydough.metadata.graphs import GraphMetadata +from pydough.pydough_ast import AstNodeBuilder +from pydough.pydough_ast import pydough_operators as pydop @pytest.fixture(scope="session") @@ -42,7 +43,7 @@ def invalid_graph_path() -> str: @pytest.fixture(scope="session") -def valid_sample_graph_names() -> Set[str]: +def valid_sample_graph_names() -> set[str]: """ Set of valid names to use to access a sample graph. """ @@ -60,7 +61,7 @@ def sample_graph_names(request) -> str: @pytest.fixture def get_sample_graph( sample_graph_path: str, - valid_sample_graph_names: Set[str], + valid_sample_graph_names: set[str], ) -> graph_fetcher: """ A function that takes in the name of a graph from the supported sample @@ -79,7 +80,7 @@ def impl(name: str) -> GraphMetadata: @pytest.fixture def get_sample_graph_nouns( - sample_graph_nouns_path: str, valid_sample_graph_names: Set[str] + sample_graph_nouns_path: str, valid_sample_graph_names: set[str] ) -> noun_fetcher: """ A function that takes in the name of a graph (currently only supports the @@ -87,11 +88,11 @@ def get_sample_graph_nouns( PyDough graph. """ - def impl(name: str) -> MutableMapping[str, Set[str]]: + def impl(name: str) -> MutableMapping[str, set[str]]: if name not in valid_sample_graph_names: raise Exception(f"Unrecognized graph name '{name}'") - nouns: MutableMapping[str, Set[str]] - with open(sample_graph_nouns_path, "r") as f: + nouns: MutableMapping[str, set[str]] + with open(sample_graph_nouns_path) as f: nouns = json.load(f)[name] # Convert the noun values for each name from a list to a set return map_over_dict_values(nouns, set) diff --git a/tests/test_ast_collection.py b/tests/test_ast_collection.py index 130eb6b5..5d2d1fe5 100644 --- a/tests/test_ast_collection.py +++ b/tests/test_ast_collection.py @@ -2,30 +2,32 @@ TODO: add file-level docstring. """ -from typing import Set, MutableMapping, Tuple -from pydough.types import ( - StringType, - Float64Type, - Int64Type, -) -from pydough.pydough_ast import AstNodeBuilder, PyDoughCollectionAST +from collections.abc import MutableMapping + +import pytest from test_utils import ( + BackReferenceCollectionInfo, + BackReferenceExpressionInfo, + CalcInfo, + ChildReferenceInfo, CollectionTestInfo, - LiteralInfo, FunctionInfo, + LiteralInfo, ReferenceInfo, - BackReferenceExpressionInfo, - TableCollectionInfo, SubCollectionInfo, - CalcInfo, - ChildReferenceInfo, - BackReferenceCollectionInfo, + TableCollectionInfo, +) + +from pydough.pydough_ast import AstNodeBuilder, PyDoughCollectionAST +from pydough.types import ( + Float64Type, + Int64Type, + StringType, ) -import pytest @pytest.fixture -def region_intra_ratio() -> Tuple[CollectionTestInfo, str, str]: +def region_intra_ratio() -> tuple[CollectionTestInfo, str, str]: """ The AST node info for a query that calculates the ratio for each region between the of all part sale values (retail price of the part times the @@ -639,7 +641,7 @@ def region_intra_ratio() -> Tuple[CollectionTestInfo, str, str]: def test_collections_calc_terms( calc_pipeline: CollectionTestInfo, expected_calcs: MutableMapping[str, int], - expected_total_names: Set[str], + expected_total_names: set[str], tpch_node_builder: AstNodeBuilder, ): """ @@ -1027,7 +1029,7 @@ def test_collections_to_string( def test_regions_intra_ratio_to_string( - region_intra_ratio: Tuple[CollectionTestInfo, str, str], + region_intra_ratio: tuple[CollectionTestInfo, str, str], tpch_node_builder: AstNodeBuilder, ): """ diff --git a/tests/test_ast_collection_errors.py b/tests/test_ast_collection_errors.py index 4815f162..216dd6f3 100644 --- a/tests/test_ast_collection_errors.py +++ b/tests/test_ast_collection_errors.py @@ -3,17 +3,19 @@ """ import re -from pydough.pydough_ast import AstNodeBuilder + +import pytest from test_utils import ( AstNodeTestInfo, - ReferenceInfo, - TableCollectionInfo, - SubCollectionInfo, - CalcInfo, BackReferenceExpressionInfo, + CalcInfo, ChildReferenceInfo, + ReferenceInfo, + SubCollectionInfo, + TableCollectionInfo, ) -import pytest + +from pydough.pydough_ast import AstNodeBuilder @pytest.mark.parametrize( diff --git a/tests/test_ast_expression.py b/tests/test_ast_expression.py index 081c1b6f..204b923b 100644 --- a/tests/test_ast_expression.py +++ b/tests/test_ast_expression.py @@ -3,31 +3,33 @@ """ from datetime import date -from pydough.types import ( - PyDoughType, - StringType, - Float64Type, - BooleanType, - DateType, - Int64Type, - DecimalType, + +import pytest +from test_utils import ( + AstNodeTestInfo, + ColumnInfo, + FunctionInfo, + LiteralInfo, + graph_fetcher, ) + from pydough.pydough_ast import ( - PyDoughAST, AstNodeBuilder, ColumnProperty, ExpressionFunctionCall, Literal, + PyDoughAST, PyDoughExpressionAST, ) -from test_utils import ( - graph_fetcher, - AstNodeTestInfo, - LiteralInfo, - ColumnInfo, - FunctionInfo, +from pydough.types import ( + BooleanType, + DateType, + DecimalType, + Float64Type, + Int64Type, + PyDoughType, + StringType, ) -import pytest @pytest.mark.parametrize( diff --git a/tests/test_ast_expression_errors.py b/tests/test_ast_expression_errors.py index 25fa6812..6da192c2 100644 --- a/tests/test_ast_expression_errors.py +++ b/tests/test_ast_expression_errors.py @@ -2,18 +2,19 @@ TODO: add file-level docstring. """ -from pydough.pydough_ast import ( - PyDoughASTException, - AstNodeBuilder, - pydough_operators as pydop, -) import re - import pytest - from test_utils import AstNodeTestInfo, FunctionInfo, graph_fetcher +from pydough.pydough_ast import ( + AstNodeBuilder, + PyDoughASTException, +) +from pydough.pydough_ast import ( + pydough_operators as pydop, +) + def test_binop_wrong_num_args(binary_operators: pydop.BinaryOperator): """ diff --git a/tests/test_expression_type_deducer.py b/tests/test_expression_type_deducer.py index 84fbacf8..a21a1a83 100644 --- a/tests/test_expression_type_deducer.py +++ b/tests/test_expression_type_deducer.py @@ -2,12 +2,15 @@ TODO: add file-level docstring. """ -from typing import MutableSequence -from pydough.types import StringType, Int64Type, PyDoughType -from pydough.pydough_ast import PyDoughAST, AstNodeBuilder, pydough_operators as pydop +from collections.abc import MutableSequence + import pytest from test_utils import AstNodeTestInfo, LiteralInfo +from pydough.pydough_ast import AstNodeBuilder, PyDoughAST +from pydough.pydough_ast import pydough_operators as pydop +from pydough.types import Int64Type, PyDoughType, StringType + @pytest.mark.parametrize( "deducer, args_info, expected_type", diff --git a/tests/test_expression_type_deducer_errors.py b/tests/test_expression_type_deducer_errors.py index 0129d2b5..618b78c7 100644 --- a/tests/test_expression_type_deducer_errors.py +++ b/tests/test_expression_type_deducer_errors.py @@ -2,17 +2,21 @@ TODO: add file-level docstring. """ -from typing import MutableSequence +import re +from collections.abc import MutableSequence + +import pytest +from test_utils import AstNodeTestInfo, LiteralInfo + from pydough.pydough_ast import ( + AstNodeBuilder, PyDoughAST, PyDoughASTException, - AstNodeBuilder, +) +from pydough.pydough_ast import ( pydough_operators as pydop, ) -import re -import pytest from pydough.types import StringType -from test_utils import AstNodeTestInfo, LiteralInfo @pytest.mark.parametrize( diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 0a736802..71168a62 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -2,34 +2,35 @@ TODO: add file-level docstring """ +from collections import defaultdict +from collections.abc import MutableMapping, MutableSequence + import pytest -from pydough.metadata.abstract_metadata import AbstractMetadata +from test_utils import graph_fetcher, map_over_dict_values, noun_fetcher + from pydough.metadata import ( - GraphMetadata, CollectionMetadata, + CompoundRelationshipMetadata, + GraphMetadata, PropertyMetadata, + SimpleJoinMetadata, SimpleTableMetadata, TableColumnMetadata, - SimpleJoinMetadata, - CompoundRelationshipMetadata, ) +from pydough.metadata.abstract_metadata import AbstractMetadata from pydough.metadata.properties import ( - SubcollectionRelationshipMetadata, InheritedPropertyMetadata, + SubcollectionRelationshipMetadata, ) -from typing import MutableSequence, MutableMapping, Set -from collections import defaultdict from pydough.types import ( - StringType, - Int8Type, - Int64Type, DateType, DecimalType, + Int8Type, + Int64Type, PyDoughType, + StringType, ) -from test_utils import graph_fetcher, noun_fetcher, map_over_dict_values - def test_graph_structure(sample_graphs: GraphMetadata): """ @@ -168,10 +169,10 @@ def test_get_sample_graph_nouns( graph: GraphMetadata = get_sample_graph(sample_graph_names) nouns: MutableMapping[str, MutableSequence[AbstractMetadata]] = graph.get_nouns() # Transform the nouns from metadata objects into path strings - processed_nouns: MutableMapping[str, Set[str]] = map_over_dict_values( + processed_nouns: MutableMapping[str, set[str]] = map_over_dict_values( nouns, lambda noun_values: {noun.path for noun in noun_values} ) - answer: MutableMapping[str, Set[str]] = get_sample_graph_nouns(sample_graph_names) + answer: MutableMapping[str, set[str]] = get_sample_graph_nouns(sample_graph_names) assert ( processed_nouns == answer ), f"Mismatch between names of nouns in {graph!r} versus expected values" diff --git a/tests/test_metadata_errors.py b/tests/test_metadata_errors.py index c43888ce..1fed0d91 100644 --- a/tests/test_metadata_errors.py +++ b/tests/test_metadata_errors.py @@ -2,13 +2,14 @@ TODO: add file-level docstring """ -import pytest import re -from pydough.metadata import PyDoughMetadataException, GraphMetadata, CollectionMetadata -from pydough import parse_json_metadata_from_file +import pytest from test_utils import graph_fetcher +from pydough import parse_json_metadata_from_file +from pydough.metadata import CollectionMetadata, GraphMetadata, PyDoughMetadataException + def test_missing_collection(get_sample_graph: graph_fetcher): """ diff --git a/tests/test_sqlite_connection.py b/tests/test_sqlite_connection.py index a4a888d3..070e15df 100644 --- a/tests/test_sqlite_connection.py +++ b/tests/test_sqlite_connection.py @@ -3,8 +3,10 @@ using a SQLite database backend. """ -import pytest import sqlite3 + +import pytest + from pydough.database_connectors.database_connector import DatabaseConnection diff --git a/tests/test_type_verifier.py b/tests/test_type_verifier.py index d36e8a4a..4b79dabe 100644 --- a/tests/test_type_verifier.py +++ b/tests/test_type_verifier.py @@ -2,12 +2,15 @@ TODO: add file-level docstring. """ -from typing import MutableSequence -from pydough.pydough_ast import PyDoughAST, AstNodeBuilder, pydough_operators as pydop +from collections.abc import MutableSequence + import pytest -from pydough.types import Int64Type from test_utils import AstNodeTestInfo, LiteralInfo +from pydough.pydough_ast import AstNodeBuilder, PyDoughAST +from pydough.pydough_ast import pydough_operators as pydop +from pydough.types import Int64Type + @pytest.mark.parametrize( "verifier, args_info", diff --git a/tests/test_type_verifier_errors.py b/tests/test_type_verifier_errors.py index 4b72edc5..476ec777 100644 --- a/tests/test_type_verifier_errors.py +++ b/tests/test_type_verifier_errors.py @@ -2,16 +2,20 @@ TODO: add file-level docstring. """ -from typing import MutableSequence +from collections.abc import MutableSequence + +import pytest +from test_utils import AstNodeTestInfo, LiteralInfo + from pydough.pydough_ast import ( - PyDoughAST, AstNodeBuilder, + PyDoughAST, PyDoughASTException, +) +from pydough.pydough_ast import ( pydough_operators as pydop, ) from pydough.types import Int64Type -from test_utils import AstNodeTestInfo, LiteralInfo -import pytest @pytest.mark.parametrize( diff --git a/tests/test_types.py b/tests/test_types.py index 1b33662c..f3464cb1 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -2,11 +2,11 @@ TODO: add file-level docstring. """ -from pydough.types import parse_type_from_string +import pytest # Used so eval() has access to all the type classes from pydough.types import * # noqa -import pytest +from pydough.types import parse_type_from_string @pytest.mark.parametrize( diff --git a/tests/test_utils.py b/tests/test_utils.py index 319ddf98..a508ef35 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -19,19 +19,21 @@ "BackReferenceCollectionInfo", ] +from abc import ABC, abstractmethod +from collections.abc import Callable, MutableMapping, MutableSequence +from typing import Any + from pydough.metadata import GraphMetadata from pydough.pydough_ast import ( AstNodeBuilder, + Calc, + CalcChildCollection, PyDoughAST, PyDoughCollectionAST, PyDoughExpressionAST, - Calc, - CalcChildCollection, ) from pydough.pydough_ast.collections import CollectionAccess -from typing import MutableMapping, Set, Callable, Any, MutableSequence, Tuple from pydough.types import PyDoughType -from abc import ABC, abstractmethod # Type alias for a function that takes in a string and generates metadata # for a graph based on it. @@ -39,7 +41,7 @@ # Type alias for a function that takes in a string and generates the # representation of all the nouns in a metadata graphs based on it. -noun_fetcher = Callable[[str], MutableMapping[str, Set[str]]] +noun_fetcher = Callable[[str], MutableMapping[str, set[str]]] def map_over_dict_values( @@ -416,7 +418,7 @@ class CalcInfo(CollectionTestInfo): def __init__(self, children, **kwargs): super().__init__() self.children_info: MutableSequence[CollectionTestInfo] = children - self.args: MutableSequence[Tuple[str, AstNodeTestInfo]] = list(kwargs.items()) + self.args: MutableSequence[tuple[str, AstNodeTestInfo]] = list(kwargs.items()) def to_string(self) -> str: args_strings: MutableSequence[str] = [ @@ -441,7 +443,7 @@ def local_build( children.append(child) raw_calc = builder.build_calc(context, children) assert isinstance(raw_calc, Calc) - args: MutableSequence[Tuple[str, PyDoughExpressionAST]] = [] + args: MutableSequence[tuple[str, PyDoughExpressionAST]] = [] for name, info in self.args: expr = info.build(builder, context, children) assert isinstance(expr, PyDoughExpressionAST) diff --git a/tpch_demo/test_tpch_download.py b/tpch_demo/test_tpch_download.py index 0d129fb9..a4c9faf5 100644 --- a/tpch_demo/test_tpch_download.py +++ b/tpch_demo/test_tpch_download.py @@ -6,9 +6,9 @@ import os import sqlite3 import typing as pt +from collections.abc import Iterator import pytest -from typing import Iterator @pytest.fixture(scope="module") From 09b9c8ed2fdf1a611b5a069ea02b8ce36a311262 Mon Sep 17 00:00:00 2001 From: knassre-bodo Date: Tue, 5 Nov 2024 16:51:58 -0500 Subject: [PATCH 2/3] [RUN CI] From c90a4960b8b64588eaac95b2fe341ceb3f47de59 Mon Sep 17 00:00:00 2001 From: knassre-bodo Date: Wed, 6 Nov 2024 10:09:44 -0500 Subject: [PATCH 3/3] Revisions [RUN CI] --- .../pydough_ast/collections/calc_child_collection.py | 12 ++++-------- pyproject.toml | 4 ++++ tests/test_ast_collection.py | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pydough/pydough_ast/collections/calc_child_collection.py b/pydough/pydough_ast/collections/calc_child_collection.py index 05c357b0..d6173c23 100644 --- a/pydough/pydough_ast/collections/calc_child_collection.py +++ b/pydough/pydough_ast/collections/calc_child_collection.py @@ -54,7 +54,7 @@ def to_string(self) -> str: if isinstance(self.collection_access, HiddenBackReferenceCollection): return self.collection_access.alias elif isinstance(self.collection_access, BackReferenceCollection): - return self.collection_access.term_name + return self.collection_access.to_string() elif isinstance(self.collection_access, TableCollection): return self.collection_access.collection.name elif isinstance(self.collection_access, SubCollection): @@ -71,14 +71,10 @@ def to_tree_form(self) -> CollectionTreeForm: has_successor=not self.is_last, ) item_str: str - if isinstance( - self.collection_access, SubCollection | HiddenBackReferenceCollection - ): - item_str = f"SubCollection[{self.to_string()}]" - elif isinstance(self.collection_access, BackReferenceCollection): - item_str = f"SubCollection[{self.collection_access.to_string()}]" - else: + if isinstance(self.collection_access, TableCollection): item_str = f"TableCollection[{self.to_string()}]" + else: + item_str = f"SubCollection[{self.to_string()}]" return CollectionTreeForm( item_str, predecessor.depth + 1, diff --git a/pyproject.toml b/pyproject.toml index 70917b6c..f96e304d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,4 +22,8 @@ lint.extend-select = [ "UP", # pyupgrade "C4", # flake8-comprehensions "TID", # flake8-tidy-imports +] + +lint.ignore = [ + "UP038", ] \ No newline at end of file diff --git a/tests/test_ast_collection.py b/tests/test_ast_collection.py index 5d2d1fe5..58130fed 100644 --- a/tests/test_ast_collection.py +++ b/tests/test_ast_collection.py @@ -905,7 +905,7 @@ def test_collections_calc_terms( [ChildReferenceInfo("quantity", 0), ReferenceInfo("ps_availqty")], ), ), - "Suppliers.parts_supplied(nation_name=nation(nation_name=name).nation_name, supplier_name=BACK(1).name, part_name=name, ratio=ps_lines.quantity / ps_availqty)", + "Suppliers.parts_supplied(nation_name=BACK(1).nation(nation_name=name).nation_name, supplier_name=BACK(1).name, part_name=name, ratio=ps_lines.quantity / ps_availqty)", """\ ──┬─ TPCH └─┬─ TableCollection[Suppliers] @@ -942,7 +942,7 @@ def test_collections_calc_terms( part_name=ReferenceInfo("name"), ratio=ChildReferenceInfo("ratio", 0), ), - "Suppliers.parts_supplied(nation_name=nation.name, supplier_name=BACK(1).name, part_name=name, ratio=ps_lines(ratio=quantity / BACK(1).ps_availqty).ratio)", + "Suppliers.parts_supplied(nation_name=BACK(1).nation.name, supplier_name=BACK(1).name, part_name=name, ratio=ps_lines(ratio=quantity / BACK(1).ps_availqty).ratio)", """\ ──┬─ TPCH └─┬─ TableCollection[Suppliers]