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

Fix new mypy 1.12 errors #284

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions arraycontext/container/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ def is_array_field(f: Field) -> bool:
f"Field '{f.name}' union contains non-array container "
"arguments. All arguments must be array containers.")

if isinstance(f.type, str):
Copy link
Collaborator Author

@alexfikl alexfikl Oct 14, 2024

Choose a reason for hiding this comment

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

f.type is now correctly a Union[type[Any], str], which disagreed with is_array_type below. This just moves the check out of if __debug__ to let mypy know we handle that case.

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds good. In the short-ish term, we'll probably need to handle this case better, too. Maybe just tossing it to parse might be enough? (though some of the identifiers may not resolve?) At any rate, a discussion for a different day.

raise TypeError(
f"String annotation on field '{f.name}' not supported. "
"(this may be due to 'from __future__ import annotations')")

if __debug__:
if not f.init:
raise ValueError(
f"'init=False' field not allowed: '{f.name}'")

if isinstance(f.type, str):
raise TypeError(
f"string annotation on field '{f.name}' not supported")
f"Field with 'init=False' not allowed: '{f.name}'")

# NOTE:
# * `_BaseGenericAlias` catches `List`, `Tuple`, etc.
Expand All @@ -102,12 +103,12 @@ def is_array_field(f: Field) -> bool:
if isinstance(f.type, (_BaseGenericAlias, _SpecialForm)):
# NOTE: anything except a Union is not allowed
raise TypeError(
f"typing annotation not supported on field '{f.name}': "
f"Typing annotation not supported on field '{f.name}': "
f"'{f.type!r}'")

if not isinstance(f.type, type):
raise TypeError(
f"field '{f.name}' not an instance of 'type': "
f"Field '{f.name}' not an instance of 'type': "
f"'{f.type!r}'")

return is_array_type(f.type)
Expand Down
4 changes: 2 additions & 2 deletions arraycontext/container/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def rec(*_args: Any) -> Any:

new_args[i] = subary

result.append((key, frec(*new_args))) # type: ignore[operator]
result.append((key, frec(*new_args)))

return process_container(template_ary, result) # type: ignore[operator]
return process_container(template_ary, result)

# }}}

Expand Down
Loading