mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
Core: fix settings API for removal of Python 3.8, 3.9 (#4280)
* Core: fix settings API for removal of Python 3.8, 3.9 This is fixing 2 problems: - The `World` class has the annotation: `settings: ClassVar[Optional["Group"]]` so `MyWorld.settings` should not raise an exception like it does for some worlds. With the `Optional` there, it looks like it should return `None` for the worlds that don't use it. So that's what I changed it to. - `Group.update` had some code that required `typing.Union` instead of the Python 3.10 `|` for unions. added unit test for this fix added change in Zillion that I used to discover this problem and used it to test the test * fix copy-pasted stuff * tuple instead of set Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com> --------- Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
10
settings.py
10
settings.py
@@ -7,6 +7,7 @@ import os
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
import types
|
||||
import typing
|
||||
import warnings
|
||||
from enum import IntEnum
|
||||
@@ -162,8 +163,13 @@ class Group:
|
||||
else:
|
||||
# assign value, try to upcast to type hint
|
||||
annotation = self.get_type_hints().get(k, None)
|
||||
candidates = [] if annotation is None else \
|
||||
typing.get_args(annotation) if typing.get_origin(annotation) is Union else [annotation]
|
||||
candidates = (
|
||||
[] if annotation is None else (
|
||||
typing.get_args(annotation)
|
||||
if typing.get_origin(annotation) in (Union, types.UnionType)
|
||||
else [annotation]
|
||||
)
|
||||
)
|
||||
none_type = type(None)
|
||||
for cls in candidates:
|
||||
assert isinstance(cls, type), f"{self.__class__.__name__}.{k}: type {cls} not supported in settings"
|
||||
|
Reference in New Issue
Block a user