Skip to content

Commit

Permalink
Let grpc do validation instead of typeguard
Browse files Browse the repository at this point in the history
Typeguard does not seem to work on Optional[str]
as

```python

from typing import Optional
from typeguard import typechecked

@TypeChecked()
def foo(filename: Optional[str] = None) -> None:
   print(filename)

foo(42)
```
Raises no error
  • Loading branch information
sverhoeven committed Jun 26, 2023
1 parent 6034be4 commit d96b5a2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
2 changes: 0 additions & 2 deletions grpc4bmi/bmi_grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from bmipy import Bmi
import grpc
import numpy
from typeguard import typechecked

from grpc_status import rpc_status
from google.rpc import error_details_pb2
Expand Down Expand Up @@ -94,7 +93,6 @@ def get_unique_port(host=None):
s.bind(("" if host is None else host, 0))
return int(s.getsockname()[1])

@typechecked
def initialize(self, filename: Optional[str]):
fname = "" if filename is None else filename
try:
Expand Down
3 changes: 1 addition & 2 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from google.rpc import error_details_pb2, status_pb2, code_pb2
from grpc_status import rpc_status
from heat import BmiHeat
from typeguard import TypeCheckError

from grpc4bmi.bmi_grpc_server import BmiServer
from grpc4bmi.bmi_grpc_client import BmiClient, RemoteException, handle_error
Expand Down Expand Up @@ -109,7 +108,7 @@ def test_initialize():
def test_initialize_with_nonstring():
client, local = make_bmi_classes(False)
assert client is not None
with pytest.raises(TypeCheckError, match='did not match any element in the union'):
with pytest.raises(TypeError, match='bad argument type for built-in operation'):
client.initialize(42)
client.finalize()
del client
Expand Down

0 comments on commit d96b5a2

Please sign in to comment.