pyright-python
pyright-python copied to clipboard
Different behaviour with or without the pre-commit hook (reportAttributeAccessIssue)
Hi there,
When running pre-commit run
with the environment given below, I get this error
error: "run_data_generator" is not a known attribute of module "examples.python_scripts.generating_trajectory_data.trajectory_generator"(reportAttributeAccessIssue)
while running pyright
does not return any error.
Could you explain why this behaviour is observed?
Working tree:
control_dde/
├── examples/
│ ├── __init__.py
│ └── python_scripts/
│ ├── __init__.py
│ └── generating_trajectory_data/
│ ├── __init__.py
│ └── trajectory_generator.py
└── test/
└── test_generator_and_training.py
test_generator_and_training.py
import pathlib
from typing import Any, Generator
import pytest
from control_dde.utils import PATH_PROJECT_ROOT
from examples.python_scripts.generating_trajectory_data import trajectory_generator
@pytest.fixture(params=[94])
def seed(request) -> Generator[int, None, None]:
yield request.param
@pytest.fixture(params=["debug_pytest"])
def mlflow_experiment_name(request) -> Generator[str, None, None]:
yield request.param
@pytest.fixture(params=["unique_trajectory_divided", "multiple_trajectories"])
def data_type(request) -> Generator[str, None, None]:
yield request.param
@pytest.fixture(params=[20])
def num_steps(request) -> Generator[int, None, None]:
yield request.param
@pytest.fixture(params=["zero", "uniform"])
def control_type(request) -> Generator[str, None, None]:
yield request.param
@pytest.fixture(params=[1, 4])
def num_trajectories(request) -> Generator[int, None, None]:
yield request.param
@pytest.fixture(
params=["pendulum", "mackey_glass", "vanderpol", "linear_time_invariant"]
)
def env_name(request) -> Generator[str, None, None]:
yield request.param
@pytest.fixture
def dict_env_params() -> dict[str, Any]:
return {
"pendulum": {},
"mackey_glass": {},
"vanderpol": {},
"linear_time_invariant": {
"dt": 0.01,
"matrix_a": [[1, 2], [3, 4]],
"matrix_b": [[-1], [-2]],
"matrix_c": [[0, 1]],
"control_penalty": 1,
"dtype": "float32",
},
}
@pytest.fixture
def dict_configuration(
seed: int,
mlflow_experiment_name: str,
data_type: str,
num_steps: int,
control_type: str,
num_trajectories: int,
env_name: str,
dict_env_params: dict[str, Any],
) -> dict[str, Any]:
return {
"seed": seed,
"mlflow_experiment_name": mlflow_experiment_name,
"data": {
"type": data_type,
"num_steps": num_steps,
"control_type": control_type,
"num_trajectories": num_trajectories,
},
"env": {"name": env_name, "params": dict_env_params[env_name]},
}
def test_generator_from_list_configurations(dict_configuration: dict[str, Any]):
trajectory_generator.run_data_generator(
dict_config=dict_configuration,
path_config_absolute=None,
path_project_root=pathlib.Path(PATH_PROJECT_ROOT),
plot_trajectory_data=True,
)
pyrightconfig.json
{
"venvPath": "venv",
"venv": "venv_control_dde",
}
.pre-commit-config.yaml
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.373
hooks:
- id: pyright
exclude: 'oderl/.*'
files: "."
args: ["--pythonpath", "."]
additional_dependencies: [ torch, pytest, typing_extensions, jaxtyping, matplotlib, gymnasium, seaborn, torchvision, scipy ]