Skip to content

Commit

Permalink
Merge pull request #22 from numpy/another-attempt-at-fixing-mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham authored Feb 3, 2025
2 parents ecd2840 + 18c39e9 commit 45b5dfc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"evenBetterToml.formatter.indentString": " ",
"evenBetterToml.formatter.indentTables": true,
"evenBetterToml.formatter.trailingNewline": true,
"mypy-type-checker.path": ["uv", "run", "--directory=test", "static", "bmp"]
"mypy-type-checker.path": ["uv", "run", "--project=test", "static", "bmp"]
}
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ classifiers = [
"Typing :: Typed",
]
requires-python = ">=3.10"
packages = [{include = "src/numpy-stubs" }]
dependencies = []


[project.optional-dependencies]
numpy = ["numpy>=2.2.2,<2.3"]

Expand Down Expand Up @@ -68,8 +70,14 @@ packages = ["src/numpy-stubs"]

[tool.mypy]
python_version = "3.10"
strict = true
mypy_path = "src"

pretty = false
show_error_context = false
show_error_code_links = false
show_traceback = false

strict = true
disable_bytearray_promotion = true
disable_memoryview_promotion = true
enable_error_code = ["ignore-without-code", "truthy-bool"]
Expand All @@ -93,7 +101,7 @@ include = [
"tool",
]
ignore = [".venv", "test/.venv"]
stubPath = "src"
stubPath = "."
pythonPlatform = "All"
pythonVersion = "3.10"
typeCheckingMode = "standard" # TODO(jorenham): set to "all"
Expand Down Expand Up @@ -124,7 +132,7 @@ strictGenericNarrowing = true


[tool.ruff]
src = ["src", "test", "tool"]
src = ["src/numpy-stubs", "test", "tool"]
extend-exclude = [".git", ".mypy_cache", ".tox", ".venv"]
force-exclude = true
# https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#maximum-line-length
Expand Down
19 changes: 18 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# numtype-test
# NumType testing

Mypy and basedmypy will only recognize the `src/numpy-stubs` if `numtype` is installed in an
isolated project, and it cannot be editable.
The private `numtype-test` project in this directory provides entrypoints that will run basedmypy
and basedpyright.

To run basedmypy (`bmp` for short) on the static tests, run

```bash
uv run static <bmp|bpr|all> [OPTIONS]
```

Here, `bmp` runs (based)`mypy`, `bpr` runs `basedpyright`, and `all` runs both.
If no options are provided, it defaults to `static/`.

To run this form the root `numtype` directory, you can pass an additional `--project=test` flag
to the `uv run` command (i.e. before `static`).
10 changes: 3 additions & 7 deletions test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ def _static_bmp(args: list[str], /) -> int:
return _call_static(
args,
"mypy",
"--explicit-package-bases",
"--hide-error-context",
"--hide-error-code-links",
"--no-pretty",
"--tb",
"--config-file=../pyproject.toml",
"--config-file",
str(PROJECT_PATH / "pyproject.toml"),
)


def _static_bpr(args: list[str], /) -> int:
return _call_static(args, "basedpyright", "--project=../")
return _call_static(args, "basedpyright", "--project", str(PROJECT_PATH))


def static(args: list[str] | None = None, /) -> int:
Expand Down
12 changes: 9 additions & 3 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ requires-python = ">=3.10"
dependencies = [
"numtype",
"basedmypy[faster-cache]>=2.9.1",
# "mypy[faster-cache]>=1.14.1",
"basedpyright>=1.26.0",
]

[project.scripts]
static = "main:static"

[tool.uv.sources]
numtype = {path = ".."}
[tool.uv]
reinstall-package = ["numtype"]

[tool.uv.pip]
strict = true

[tool.uv.sources]
numtype = {path = ".."}

[tool.hatch.build]
packages = ["."]

0 comments on commit 45b5dfc

Please sign in to comment.