Skip to content

Commit

Permalink
chore: Add pyright config and resolve issues (#12)
Browse files Browse the repository at this point in the history
* chore: Add pyright config

* style: Fix pyright issues
  • Loading branch information
leoschleier authored Dec 10, 2023
1 parent 2cbc079 commit 2c9bbcc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
19 changes: 12 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.black]
line-length = 79

[tool.pyright]
venvPath = "."
venv = ".venv"
typeCheckingMode = "strict"
include = ["src", "tests"]
pythonVersion = "3.11"

[tool.ruff]
select = ["ALL"]
ignore = ["ANN101", "ANN102"] # Type annotations for 'self' and 'cls'
fixable = ["ALL"]
fix = false
fix = true
line-length = 79
target-version = "py311"

Expand All @@ -54,9 +63,5 @@ convention = "numpy"
"tests/*" = ["S101"] # Use of assert detected


[tool.black]
line-length = 79


[tool.pytest.ini_options]
pythonpath = ["src"]
pythonpath = ["src"]
7 changes: 4 additions & 3 deletions src/pit/viper/env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Load environment variables from a `.env` file."""
import os
from pathlib import Path
from typing import Self

_EQUALS = "="
_NEW_LINE = "\n"
Expand All @@ -11,9 +12,9 @@
class UnsupportedFileFormatError(Exception):
"""Raised when the file format is not supported."""

def __init__(self, path: Path) -> None:
def __init__(self: Self, path: Path) -> None:
"""Initialize the exception."""
super().__init__(f"Unsupported file format: {path.suffix()}")
super().__init__(f"Unsupported file format: {path.suffix}")


def auto_env(
Expand Down Expand Up @@ -73,7 +74,7 @@ def _populate_env(*, path: Path, overwrite: bool = False) -> None:
_set_variable(key=k, value=v, overwrite=overwrite)


def _set_variable(key: str, value: str, *, overwrite: bool = False) -> str:
def _set_variable(key: str, value: str, *, overwrite: bool = False) -> None:
"""Set an environment variable."""
if overwrite:
os.environ[key] = value
Expand Down
6 changes: 3 additions & 3 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import os
from pathlib import Path

import py
import py # pyright: ignore [reportMissingTypeStubs]
import pytest
from pit.viper import env

_TEST_DOTENV_PATH = Path(__file__).parent / "data" / ".env"


@pytest.fixture(autouse=True)
def _prepare_env() -> None:
def _prepare_env() -> None: # pyright: ignore [reportUnusedFunction]
"""Prepare the environment for testing."""
os.environ.pop("FOO", None)
os.environ.pop("TEST_VAR", None)
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_auto_env_with_overwrite() -> None:
assert e["TEST_VAR"] == "test_value"


def test_auto_env_with_non_existing_path(tmpdir: py.path.local) -> None:
def test_auto_env_with_non_existing_path(tmpdir: py.path.LocalPath) -> None:
"""Test the `auto_env` function with a non-existing path.
We expect that the function still returns a dictionary of
Expand Down

0 comments on commit 2c9bbcc

Please sign in to comment.