Skip to content

Commit b471eca

Browse files
committed
Fix type of get default
Was returning None for non-None defaults.
1 parent 8f1e90c commit b471eca

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed type of default parameter for `EntityComponents.get`.
13+
1014
## [5.2.0] - 2024-07-22
1115

1216
### Changed

tcod/ecs/entity.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,17 @@ def __ior__(
529529
self.update(value)
530530
return self
531531

532-
def get(self, __key: ComponentKey[T], __default: T | None = None) -> T | None:
532+
@overload
533+
def get(self, __key: ComponentKey[T]) -> T | None: ...
534+
@overload
535+
def get(self, __key: ComponentKey[T], __default: _T1) -> T | _T1: ...
536+
537+
def get(self, __key: ComponentKey[T], __default: _T1 | None = None) -> T | _T1:
533538
"""Return a component, returns None or a default value when the component is missing."""
534539
try:
535540
return self[__key]
536541
except KeyError:
537-
return __default
542+
return __default # type: ignore[return-value] # https://github.com/python/mypy/issues/3737
538543

539544
def setdefault(self, __key: ComponentKey[T], __default: T) -> T: # type: ignore[override]
540545
"""Assign a default value if a component is missing, then returns the current value."""

0 commit comments

Comments
 (0)