inducer / arraycontext

Choose your favorite numpy-workalike!
6 stars 11 forks source link

Ignore mypy false positive #275

Closed alexfikl closed 2 months ago

alexfikl commented 2 months ago

Haven't managed to track down the actual issue, but the error here goes away if tag_dataclass is replaced with just dataclass. mypy has multiple dataclass_transform issues still open, so it's likely not quite ironed out..

Gitlab is passing though: https://gitlab.tiker.net/fikl2/arraycontext/-/pipelines/575042

alexfikl commented 2 months ago

Hm.. great :(

alexfikl commented 2 months ago

@inducer Dug into this a bit more and it seems like the problem is that we pin python_version = "3.8" but the dataclass_transform is a python 3.11 feature, so mypy doesn't know what to do about it. Making the same pin in pytato also yells about all the classes using tag_dataclass.

From what I can tell the possible fixes are: bump the mypy python version or ignore it harder (i.e. add a temporary unused-ignore too). What would you prefer?

EDIT: The main difference between Github and Gitlab seems to be that one builds with conda and the other with pip. I haven't managed to see which package is different and causes the mismatch in errors..

inducer commented 2 months ago

Thanks for digging into this! So is the overall issue intermittent? (Given that it passed here when it, IIUC, wasn't expected to?) Is there a mypy issue we can point to? To my mind, a Py3.8 codebase that imports 3.11 stuff from typing_extensions should be perfectly fine?

alexfikl commented 2 months ago

So is the overall issue intermittent? (Given that it passed here when it, IIUC, wasn't expected to?)

It's not intermittent. It's seems to pass consistently on Github in the conda env and fail consistently on Gitlab in the pip virtual env. I see the same failures locally as on Gitlab.

To my mind, a Py3.8 codebase that imports 3.11 stuff from typing_extensions should be perfectly fine?

Yeah, agreed, not sure why mypy is confused about it here..

alexfikl commented 2 months ago

Bleah, I think I know what it doesn't like. Gitlab seems to install pytools from git and Github from conda (or something?).

This simple reproducer fails for me. If you only import typing_extensions, it works just fine :( So I guess mypy is confused by the try.. except?

from __future__ import annotations

from dataclasses import dataclass
from typing import TypeVar

try:
    from typing import dataclass_transform
except ImportError:
    from typing_extensions import dataclass_transform

T = TypeVar("T")

@dataclass_transform(eq_default=True, frozen_default=True)
def tag(cls: type[T]) -> type[T]:
    return dataclass(init=True, frozen=True, eq=True, repr=True)(cls)

@tag
class Tag:
    pass

@tag
class UniqueTag(Tag):
    pass

@tag
class _BaseNamedTag(Tag):
    pass

@tag
class SomeTag(_BaseNamedTag):
    name: str

t1 = Tag()
t2 = SomeTag("name")
alexfikl commented 2 months ago

I'll go ahead and close this since it just needs a new pytools with the fix.