Skip to content

Commit

Permalink
Fix type annotation of protos.
Browse files Browse the repository at this point in the history
  • Loading branch information
coufon committed Dec 17, 2023
1 parent 4493e80 commit 851647b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install mypy pylint pytest mock
- name: Install runtime dependencies
- name: Install runtime dependencies and Space
working-directory: ./python
run: |
pip install .[dev]
Expand Down
8 changes: 3 additions & 5 deletions python/src/space/core/fs/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

from abc import abstractmethod

from google.protobuf import message
from google.protobuf import text_format
from pyarrow import fs

from space.core.fs.base import BaseFileSystem
from space.core.fs.base import BaseFileSystem, ProtoT
from space.core.utils.protos import proto_to_text
from space.core.utils.uuids import random_id

Expand All @@ -39,7 +38,7 @@ def create_fs(self) -> fs.FileSystem:
def create_dir(self, dir_path: str) -> None:
self._fs.create_dir(dir_path)

def write_proto(self, file_path: str, msg: message.Message) -> None:
def write_proto(self, file_path: str, msg: ProtoT) -> None:
# TODO: the current implement overwrite an existing file; to support an
# to disallow overwrite.
tmp_file_path = f"{file_path}.{random_id()}.tmp"
Expand All @@ -49,8 +48,7 @@ def write_proto(self, file_path: str, msg: message.Message) -> None:

self._fs.move(tmp_file_path, file_path)

def read_proto(self, file_path: str,
empty_msg: message.Message) -> message.Message:
def read_proto(self, file_path: str, empty_msg: ProtoT) -> ProtoT:
with self._fs.open_input_file(file_path) as f:
result = text_format.Parse(f.readall(), empty_msg)
return result
Expand Down
8 changes: 5 additions & 3 deletions python/src/space/core/fs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
"""Abstract base file system."""

from abc import ABC, abstractmethod
from typing import TypeVar

from google.protobuf import message

ProtoT = TypeVar("ProtoT", bound=message.Message)


class BaseFileSystem(ABC):
"""Abstract file system."""
Expand All @@ -27,10 +30,9 @@ def create_dir(self, dir_path: str) -> None:
"""Create a new directory."""

@abstractmethod
def write_proto(self, file_path: str, msg: message.Message) -> None:
def write_proto(self, file_path: str, msg: ProtoT) -> None:
"""Write a proto message in text format to a file."""

@abstractmethod
def read_proto(self, file_path: str,
empty_msg: message.Message) -> message.Message:
def read_proto(self, file_path: str, empty_msg: ProtoT) -> ProtoT:
"""Read a proto message in text format from a file."""
4 changes: 2 additions & 2 deletions python/src/space/core/proto/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ message StorageMetadata {
// The storage type.
enum Type {
TYPE_UNSPECIFIED = 0;
// A Space dataset.
// The dataset type supports fully managed storage features.
DATASET = 1;
}
Type type = 3;

// The dataset schema.
// The storage schema.
Schema schema = 4;

// The current snapshot ID.
Expand Down
2 changes: 1 addition & 1 deletion python/src/space/core/proto/metadata_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class StorageMetadata(google.protobuf.message.Message):
type: global___StorageMetadata.Type.ValueType
@property
def schema(self) -> global___Schema:
"""The dataset schema."""
"""The storage schema."""
current_snapshot_id: builtins.int
"""The current snapshot ID."""
@property
Expand Down

0 comments on commit 851647b

Please sign in to comment.