Skip to content

Commit

Permalink
eval string annotation with fn's globals
Browse files Browse the repository at this point in the history
And remove unnecessary import from __future__
  • Loading branch information
jmao-denver committed Mar 6, 2024
1 parent b01510b commit 6f629fd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
1 change: 0 additions & 1 deletion py/server/deephaven/_jpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

""" This module is an internal module to simplify usage patterns around jpy.
"""
from __future__ import annotations

import jpy

Expand Down
19 changes: 9 additions & 10 deletions py/server/deephaven/_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending
#

from __future__ import annotations

import inspect
import re
import sys
Expand Down Expand Up @@ -113,11 +111,6 @@ def _parse_type_no_nested(annotation: Any, p_param: _ParsedParam, t: Union[type,
""" Parse a specific type (top level or nested in a top-level Union annotation) without handling nested types
(e.g. a nested Union). The result is stored in the given _ParsedAnnotation object.
"""
# when from __future__ import annotations is used, the annotation is a string, we need to eval it to get the type
# when the minimum Python version is bumped to 3.10, we'll always use eval_str in _parse_signature, so that
# annotation is already a type, and we can remove this line.
t = eval(t) if isinstance(t, str) else t

p_param.orig_types.add(t)

# if the annotation is a DH DType instance, we'll use its numpy type
Expand Down Expand Up @@ -260,10 +253,16 @@ def _parse_signature(fn: Callable) -> _ParsedSignature:
sig = inspect.signature(fn, eval_str=True)
else:
sig = inspect.signature(fn)
for n, p in sig.parameters.items():
p_sig.params.append(_parse_param(n, p.annotation))

p_sig.ret_annotation = _parse_return_annotation(sig.return_annotation)
for n, p in sig.parameters.items():
# when from __future__ import annotations is used, the annotation is a string, we need to eval it to get the type
# when the minimum Python version is bumped to 3.10, we'll always use eval_str in _parse_signature, so that
# annotation is already a type, and we can skip this step.
t = eval(p.annotation, fn.__globals__) if isinstance(p.annotation, str) else p.annotation
p_sig.params.append(_parse_param(n, t))

t = eval(sig.return_annotation, fn.__globals__) if isinstance(sig.return_annotation, str) else sig.return_annotation
p_sig.ret_annotation = _parse_return_annotation(t)
return p_sig


Expand Down
3 changes: 1 addition & 2 deletions py/server/deephaven/agg.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#
# Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
#

from __future__ import annotations
"""This module implement various aggregations that can be used in deephaven table's aggregation operations."""

from typing import List, Union, Any

Expand Down
1 change: 0 additions & 1 deletion py/server/deephaven/execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""This module gives users the ability to directly manage the Deephaven query execution context on threads, which is
critical for applications to correctly launch deferred query evaluations, such as table update operations in threads.
"""
from __future__ import annotations

from typing import Sequence, Union
from contextlib import ContextDecorator
Expand Down
2 changes: 0 additions & 2 deletions py/server/deephaven/table_listener.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#
# Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
#

""" This module provides utilities for listening to table changes. """
from __future__ import annotations

from abc import ABC, abstractmethod
from functools import wraps
Expand Down
2 changes: 0 additions & 2 deletions py/server/deephaven/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

""" This module defines functions for handling Deephaven date/time data. """

from __future__ import annotations

import datetime
from typing import Union, Optional, Literal

Expand Down

0 comments on commit 6f629fd

Please sign in to comment.