Skip to content

Commit 6b52144

Browse files
authored
chore: Add typeguard to typecheck API usage (#2812)
* chore: Add typeguard to typecheck API usage Signed-off-by: Achal Shah <achals@gmail.com> * more typechecking Signed-off-by: Achal Shah <achals@gmail.com> * more typechecking Signed-off-by: Achal Shah <achals@gmail.com> * more typechecking Signed-off-by: Achal Shah <achals@gmail.com> * fix docs_required and regenerate requirements file Signed-off-by: Achal Shah <achals@gmail.com> * more typechecking Signed-off-by: Achal Shah <achals@gmail.com> * more typechecking Signed-off-by: Achal Shah <achals@gmail.com> * fix fix fix Signed-off-by: Achal Shah <achals@gmail.com> * fix fix fix Signed-off-by: Achal Shah <achals@gmail.com>
1 parent c0e2ad7 commit 6b52144

22 files changed

+178
-1143
lines changed

sdk/python/feast/aggregation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from typing import Optional
33

44
from google.protobuf.duration_pb2 import Duration
5+
from typeguard import typechecked
56

67
from feast.protos.feast.core.Aggregation_pb2 import Aggregation as AggregationProto
78

89

10+
@typechecked
911
class Aggregation:
1012
"""
1113
NOTE: Feast-handled aggregations are not yet supported. This class provides a way to register user-defined aggregations.

sdk/python/feast/data_source.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from google.protobuf.duration_pb2 import Duration
2222
from google.protobuf.json_format import MessageToJson
23+
from typeguard import typechecked
2324

2425
from feast import type_map
2526
from feast.data_format import StreamFormat
@@ -172,6 +173,7 @@ def to_proto(self) -> DataSourceProto.KinesisOptions:
172173
}
173174

174175

176+
@typechecked
175177
class DataSource(ABC):
176178
"""
177179
DataSource that can be used to source features.
@@ -371,6 +373,7 @@ def get_table_query_string(self) -> str:
371373
raise NotImplementedError
372374

373375

376+
@typechecked
374377
class KafkaSource(DataSource):
375378
def __init__(
376379
self,
@@ -579,6 +582,7 @@ def get_table_query_string(self) -> str:
579582
raise NotImplementedError
580583

581584

585+
@typechecked
582586
class RequestSource(DataSource):
583587
"""
584588
RequestSource that can be used to provide input features for on demand transforms
@@ -744,6 +748,7 @@ def source_datatype_to_feast_value_type() -> Callable[[str], ValueType]:
744748
raise NotImplementedError
745749

746750

751+
@typechecked
747752
class RequestDataSource(RequestSource):
748753
def __init__(self, *args, **kwargs):
749754
warnings.warn(
@@ -753,6 +758,7 @@ def __init__(self, *args, **kwargs):
753758
super().__init__(*args, **kwargs)
754759

755760

761+
@typechecked
756762
class KinesisSource(DataSource):
757763
def validate(self, config: RepoConfig):
758764
pass
@@ -908,6 +914,7 @@ def to_proto(self) -> DataSourceProto:
908914
return data_source_proto
909915

910916

917+
@typechecked
911918
class PushSource(DataSource):
912919
"""
913920
A source that can be used to ingest features on request

sdk/python/feast/entity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import Dict, List, Optional
1717

1818
from google.protobuf.json_format import MessageToJson
19+
from typeguard import typechecked
1920

2021
from feast.protos.feast.core.Entity_pb2 import Entity as EntityProto
2122
from feast.protos.feast.core.Entity_pb2 import EntityMeta as EntityMetaProto
@@ -24,6 +25,7 @@
2425
from feast.value_type import ValueType
2526

2627

28+
@typechecked
2729
class Entity:
2830
"""
2931
An entity defines a collection of entities for which features can be defined. An
@@ -201,7 +203,7 @@ def from_proto(cls, entity_proto: EntityProto):
201203
name=entity_proto.spec.name,
202204
join_keys=[entity_proto.spec.join_key],
203205
description=entity_proto.spec.description,
204-
tags=entity_proto.spec.tags,
206+
tags=dict(entity_proto.spec.tags),
205207
owner=entity_proto.spec.owner,
206208
)
207209

sdk/python/feast/feature_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Dict, List, Optional, Union
44

55
from google.protobuf.json_format import MessageToJson
6+
from typeguard import typechecked
67

78
from feast.base_feature_view import BaseFeatureView
89
from feast.feature_logging import LoggingConfig
@@ -21,6 +22,7 @@
2122
from feast.usage import log_exceptions
2223

2324

25+
@typechecked
2426
class FeatureService:
2527
"""
2628
A feature service defines a logical group of features from one or more feature views.

sdk/python/feast/feature_view.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Dict, List, Optional, Tuple, Type, Union
1818

1919
from google.protobuf.duration_pb2 import Duration
20+
from typeguard import typechecked
2021

2122
from feast import utils
2223
from feast.base_feature_view import BaseFeatureView
@@ -46,6 +47,7 @@
4647
DUMMY_ENTITY = Entity(name=DUMMY_ENTITY_NAME, join_keys=[DUMMY_ENTITY_ID],)
4748

4849

50+
@typechecked
4951
class FeatureView(BaseFeatureView):
5052
"""
5153
A FeatureView defines a logical group of features.

sdk/python/feast/field.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414

1515
from typing import Dict, Optional
1616

17+
from typeguard import typechecked
18+
1719
from feast.feature import Feature
1820
from feast.protos.feast.core.Feature_pb2 import FeatureSpecV2 as FieldProto
1921
from feast.types import FeastType, from_value_type
2022
from feast.value_type import ValueType
2123

2224

25+
@typechecked
2326
class Field:
2427
"""
2528
A Field represents a set of values with the same structure.

sdk/python/feast/infra/offline_stores/bigquery_source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import warnings
22
from typing import Callable, Dict, Iterable, List, Optional, Tuple
33

4+
from typeguard import typechecked
5+
46
from feast import type_map
57
from feast.data_source import DataSource
68
from feast.errors import DataSourceNotFoundException
@@ -17,6 +19,7 @@
1719
from feast.value_type import ValueType
1820

1921

22+
@typechecked
2023
class BigQuerySource(DataSource):
2124
def __init__(
2225
self,

sdk/python/feast/infra/offline_stores/file_source.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pyarrow._fs import FileSystem
55
from pyarrow._s3fs import S3FileSystem
66
from pyarrow.parquet import ParquetDataset
7+
from typeguard import typechecked
78

89
from feast import type_map
910
from feast.data_format import FileFormat, ParquetFormat
@@ -21,6 +22,7 @@
2122
from feast.value_type import ValueType
2223

2324

25+
@typechecked
2426
class FileSource(DataSource):
2527
def __init__(
2628
self,

sdk/python/feast/infra/offline_stores/redshift_source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import warnings
22
from typing import Callable, Dict, Iterable, Optional, Tuple
33

4+
from typeguard import typechecked
5+
46
from feast import type_map
57
from feast.data_source import DataSource
68
from feast.errors import DataSourceNotFoundException, RedshiftCredentialsError
@@ -17,6 +19,7 @@
1719
from feast.value_type import ValueType
1820

1921

22+
@typechecked
2023
class RedshiftSource(DataSource):
2124
def __init__(
2225
self,

sdk/python/feast/infra/offline_stores/snowflake_source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import warnings
22
from typing import Callable, Dict, Iterable, Optional, Tuple
33

4+
from typeguard import typechecked
5+
46
from feast import type_map
57
from feast.data_source import DataSource
68
from feast.feature_logging import LoggingDestination
@@ -16,6 +18,7 @@
1618
from feast.value_type import ValueType
1719

1820

21+
@typechecked
1922
class SnowflakeSource(DataSource):
2023
def __init__(
2124
self,

0 commit comments

Comments
 (0)