Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style[next]: improve typing in next.type_translation #1493

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

havogt
Copy link
Contributor

@havogt havogt commented Mar 14, 2024

No description provided.

else:
type_ = xtyping.infer_type(value, annotate_callable_kwargs=True)
symbol_type = from_type_hint(type_)

if isinstance(symbol_type, (ts.DataType, ts.CallableType, ts.OffsetType, ts.DimensionType)):
if isinstance(
symbol_type, (ts.DataType, ts.CallableType, ts.OffsetType, ts.DimensionType)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CallableType is not a TypeSpec. this looks like a bug

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CallableType is a mixin and all subtypes of it are a TypeSpec. Maybe we should rename it to something like CallableTypeMixin. If you want it to be 100% correct maybe isinstance(symbol_type, ts.CallableType) and isinstance(symbol_type, ts.TypeSpec)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by isinstance(symbol_type, ts.CallableType) and isinstance(symbol_type, ts.TypeSpec)

@havogt havogt requested a review from tehrengruber March 14, 2024 16:23
@@ -66,7 +67,7 @@ def from_type_hint(
localns: Optional[dict[str, Any]] = None,
) -> ts.TypeSpec:
recursive_make_symbol = functools.partial(from_type_hint, globalns=globalns, localns=localns)
extra_args = ()
extra_args: list = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: What is the type in the list? type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's filled from typing.get_args which returns Any, could add additional checks, but thought better than before.

@havogt havogt merged commit 424dfe2 into GridTools:main Mar 15, 2024
51 checks passed
@havogt havogt deleted the type_type_translation branch March 15, 2024 10:52
edopao pushed a commit to edopao/gt4py that referenced this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants