Skip to content

fix[next]: Reduce type ignores in client code#2484

Open
DropD wants to merge 47 commits intoGridTools:mainfrom
DropD:explicit-fbuiltins-imports
Open

fix[next]: Reduce type ignores in client code#2484
DropD wants to merge 47 commits intoGridTools:mainfrom
DropD:explicit-fbuiltins-imports

Conversation

@DropD
Copy link
Contributor

@DropD DropD commented Feb 18, 2026

Description

Partner-PR in icon4py: C2SM/icon4py#1096 (make sure this passes tests first)

Radically reduce the amount of required type ignores in client code which uses the from gt4py import next as gtx pattern.

Experimenting with this in icon4py reveals more ways in which gt4py blocks client code type checking, which have not been addressed in this PR so far:

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.

Radically reduce the amount of required type ignores in client code
which uses the `from gt4py import next as gtx` pattern.
@DropD DropD requested a review from egparedes February 18, 2026 10:42
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I just have a comment and a question

pyproject.toml Outdated
# mypy can not see through runtime logic in "fbuiltins"
disable_error_code = ["attr-defined"]
module = 'gt4py.next'

Copy link
Contributor

Choose a reason for hiding this comment

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

Question: why is this needed? What error is mypy generating here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one of these for each member:

src/gt4py/next/__init__.py:42:1: error: Module "gt4py.next.ffront.fbuiltins" does not explicitly export attribute "uint32"  [attr-defined]

I theorize it is because to determine which attributes are actually in fbuiltins.__all__, mypy would have to execute code. We are generating and concatenating lists, no idea why we do all of that dynamically at import time...

Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is that this ignore won't be needed after the suggestion above about defining fbuiltins.__all__ statically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still no, the problem being that we don't sin = make_builtin("sin") etc, but instead we do globals()[key] = BuiltInFunction(val) in a loop.

One way to fix this would be to do the analog of sin = math.sin for each of these in an if TYPE_CHECKING block. The other would be to do it more manually in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going with manually unrolling the loops for now (the asserts will catch if there is a forgotten assignment)

@DropD DropD changed the title fix[next]: Explicitly import fbuiltin members in gt4py.next fix[next]: Reduce type ignores in client code Feb 26, 2026
@DropD DropD linked an issue Feb 26, 2026 that may be closed by this pull request
@DropD
Copy link
Contributor Author

DropD commented Mar 9, 2026

cscs-ci run default

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

Looks correct to me, thanks! I have some comments and questions, many of them optional or just for my own understanding.

pyproject.toml Outdated
source-file = "src/gt4py/__about__.py"

[tool.versioningit.vcs]
default-tag = "v1.1.6"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove this from this PR. I'll try to create a tiny PR later to fix properly the versioningit warnings following this strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only here so I can run CI in the meantime.

@DropD
Copy link
Contributor Author

DropD commented Mar 12, 2026

cscs-ci run default

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.

next: dimension types are not valid types for static type checking purposes next: type hints for dsl decorators need to be improved.

2 participants