Skip to content

Commit 76f8731

Browse files
committed
Fix edge case in tcod.noise.grid
Number check needed to be more broad
1 parent cae1dc8 commit 76f8731

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- `tcod.noise.grid` would raise `TypeError` when given a plain integer for scale.
12+
913
## [18.0.0] - 2025-04-08
1014

1115
### Changed

tcod/noise.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def grid(
411411
scale: tuple[float, ...] | float,
412412
origin: tuple[int, ...] | None = None,
413413
indexing: Literal["ij", "xy"] = "xy",
414-
) -> tuple[NDArray[Any], ...]:
414+
) -> tuple[NDArray[np.number], ...]:
415415
"""Generate a mesh-grid of sample points to use with noise sampling.
416416
417417
Args:
@@ -449,7 +449,7 @@ def grid(
449449
450450
.. versionadded:: 12.2
451451
"""
452-
if isinstance(scale, float):
452+
if isinstance(scale, (int, float)):
453453
scale = (scale,) * len(shape)
454454
if origin is None:
455455
origin = (0,) * len(shape)

tests/test_noise.py

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88

99
import tcod.noise
10+
import tcod.random
1011

1112
# ruff: noqa: D103
1213

@@ -100,3 +101,7 @@ def test_noise_copy() -> None:
100101
assert repr(noise3) == repr(pickle.loads(pickle.dumps(noise3)))
101102
noise4 = tcod.noise.Noise(2, seed=42)
102103
assert repr(noise4) == repr(pickle.loads(pickle.dumps(noise4)))
104+
105+
106+
def test_noise_grid() -> None:
107+
tcod.noise.grid((2, 2), scale=2) # Check int scale

0 commit comments

Comments
 (0)