pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.03k stars 3.62k forks source link

Dataset Annotation Fail on MyPy #4632

Open gao462 opened 2 years ago

gao462 commented 2 years ago

🐛 Describe the bug

Here is my code and configuration toml file:

from torch_geometric.data import InMemoryDataset

class MyDataset(InMemoryDataset):
    pass
# Build package.
[build-system]
requires = ["setuptools>=58.2.0", "wheel>=0.37.0"]
build-backend = "setuptools.build_meta"

# Check static typing.
[tool.mypy]
plugins = "numpy.typing.mypy_plugin"
check_untyped_defs = false         # Default `--strict` mode. Loose it for convenience.
disallow_any_expr = false          # Extremely strict mode.
disallow_any_explicit = false      # Extremely strict mode.
disallow_any_generics = true       # Default `--strict` mode.
disallow_incomplete_defs = false   # Default `--strict` mode. Loose it for convenience.
disallow_subclassing_any = true    # Default `--strict` mode.
disallow_untyped_calls = false     # Default `--strict` mode. Loose it for convenience.
disallow_untyped_decorators = true # Default `--strict` mode.
disallow_untyped_defs = false      # Default `--strict` mode. Loose it for convenience.
ignore_missing_imports = true      # Used libraries are not fully annotated. Loose it for convenience.
no_implicit_optional = true        # Default `--strict` mode.
no_implicit_reexport = false       # Default `--strict` mode. Loose it for convenience.
show_error_codes = true            # Richer report.
show_error_context = true          # Richer report.
strict_equality = true             # Default `--strict` mode.
warn_redundant_casts = true        # Default `--strict` mode.
warn_return_any = true             # Default `--strict` mode.
warn_unreachable = true            # More strict mode.
warn_unused_configs = true         # Default `--strict` mode.
warn_unused_ignores = true         # Default `--strict` mode.

When I run mypy, it gives following message:

error: Class cannot subclass "InMemoryDataset" (has type "Any")  [misc]

I think the reason is pytorch geometric dataset is a subclass of torch dataset which has a generic type variable. Please update in future. Thanks.

Environment

rusty1s commented 2 years ago

Can you clarify on how we can "fix" this and what to update?