[configTools] add copy constructor to Options
This commit is contained in:
parent
5aa8986179
commit
9a0dfbd403
@ -107,8 +107,11 @@ class Options(Mapping):
|
||||
|
||||
__options: Dict[str, Option]
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, other: "Options" = None) -> None:
|
||||
self.__options = {}
|
||||
if other is not None:
|
||||
for name, option in other.items():
|
||||
self.register_option(name, option)
|
||||
|
||||
def register(
|
||||
self,
|
||||
@ -128,8 +131,8 @@ class Options(Mapping):
|
||||
self.__options[name] = option
|
||||
return option
|
||||
|
||||
def __getitem__(self, __k: str) -> Option:
|
||||
return self.__options.__getitem__(__k)
|
||||
def __getitem__(self, key: str) -> Option:
|
||||
return self.__options.__getitem__(key)
|
||||
|
||||
def __iter__(self) -> Iterator[str]:
|
||||
return self.__options.__iter__()
|
||||
|
@ -39,10 +39,7 @@ def test_ttfont_has_config():
|
||||
|
||||
def test_ttfont_can_take_superset_of_fonttools_config():
|
||||
# Create MyConfig with all options from fontTools.config plus some
|
||||
my_options = Options()
|
||||
for name, option in Config.options.items():
|
||||
my_options.register_option(name, option)
|
||||
|
||||
my_options = Options(Config.options)
|
||||
my_options.register("custom:my_option", "help", "default", str, any)
|
||||
|
||||
class MyConfig(AbstractConfig):
|
||||
|
Loading…
x
Reference in New Issue
Block a user