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

Mypy 1.15 #177

Merged
merged 2 commits into from
Feb 10, 2025
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
11 changes: 8 additions & 3 deletions pymbolic/mapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from warnings import warn

from constantdict import constantdict
from typing_extensions import ParamSpec, TypeIs
from typing_extensions import Any, ParamSpec, TypeIs

import pymbolic.primitives as p
from pymbolic.typing import ArithmeticExpression, Expression
Expand Down Expand Up @@ -200,7 +200,7 @@
else:
return self.handle_unsupported_expression(expr, *args, **kwargs)
else:
return self.map_foreign(expr, *args, **kwargs)

Check warning on line 203 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 203 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 203 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 203 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 203 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

Check warning on line 203 in pymbolic/mapper/__init__.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10

List found in expression graph. This is deprecated and will stop working in 2025. Use tuples instead.

rec = __call__

Expand Down Expand Up @@ -1506,7 +1506,12 @@
This method deliberately does not support extra arguments in mapper
dispatch, to avoid spurious dependencies of the cache on these arguments.
"""
_cse_cache_dict: dict[tuple[Expression, P.args, P.kwargs], ResultT]
_cse_cache_dict: dict[
# NOTE: "Any" because it isn not possible to use P.args, P.kwargs here.
# https://github.com/python/typing/discussions/1289#discussioncomment-4168040
# No good alternate strategy exists.
tuple[Expression, tuple[Any, ...], constantdict[str, Any]],
ResultT]

def map_common_subexpression(self,
expr: p.CommonSubexpression,
Expand All @@ -1516,7 +1521,7 @@
except AttributeError:
ccd = self._cse_cache_dict = {}

key: tuple[Expression, P.args, P.kwargs] = (
key: tuple[Expression, tuple[Any, ...], constantdict[str, Any]] = (
expr, args, constantdict(kwargs))
try:
return ccd[key]
Expand Down
10 changes: 5 additions & 5 deletions pymbolic/mapper/stringifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def __call__(self, expr, prec=PREC_NONE, *args: P.args, **kwargs: P.kwargs) -> s
return Mapper.__call__(self, expr, prec, *args, **kwargs)


class CachedStringifyMapper(StringifyMapper, CachedMapper):
class CachedStringifyMapper(StringifyMapper[P], CachedMapper):
def __init__(self) -> None:
StringifyMapper.__init__(self)
CachedMapper.__init__(self)
Expand Down Expand Up @@ -862,7 +862,7 @@ def map_product(
# {{{ simplifying, sorting stringifier


class SimplifyingSortingStringifyMapper(StringifyMapper):
class SimplifyingSortingStringifyMapper(StringifyMapper[P]):
def __init__(self, reverse=True):
super().__init__()
self.reverse = reverse
Expand Down Expand Up @@ -939,7 +939,7 @@ def map_product(
# {{{ latex stringifier


class LaTeXMapper(StringifyMapper):
class LaTeXMapper(StringifyMapper[P]):
COMPARISON_OP_TO_LATEX: ClassVar[dict[str, str]] = {
"==": r"=",
"!=": r"\ne",
Expand Down Expand Up @@ -1031,7 +1031,7 @@ def map_min(
from pytools import is_single_valued

if is_single_valued(expr.children):
return self.rec(expr.children[0], enclosing_prec)
return self.rec(expr.children[0], enclosing_prec, *args, **kwargs)

what = type(expr).__name__.lower()
return self.format(
Expand All @@ -1046,7 +1046,7 @@ def map_max(
from pytools import is_single_valued

if is_single_valued(expr.children):
return self.rec(expr.children[0], enclosing_prec)
return self.rec(expr.children[0], enclosing_prec, *args, **kwargs)

what = type(expr).__name__.lower()
return self.format(
Expand Down
Loading