graiaproject / kayaku Goto Github PK
View Code? Open in Web Editor NEWPowerful configuration solution.
License: MIT License
Powerful configuration solution.
License: MIT License
ConfigModel.it(cls: type[Self]) -> Self
# equal to
from kayaku import create
conf = create(Model)
Support handling things like types.UnionType
based unions and GenericAlias
based generics if necessary.
使用 dc schema 和 dacite
Describe the bug
dacite.exceptions.WrongTypeError
raised when a bool
property is defined in ConfigModel
Traceback (most recent call last):
File "...\test.py", line 13, in <module>
kayaku.create(TestConfig)
File "...py3.10\lib\site-packages\kayaku\model.py", line 136, in create
model_store.instance = from_dict(cls, container)
File "...py3.10\lib\site-packages\dacite\core.py", line 68, in from_dict
raise WrongTypeError(field_path=field.name, field_type=field.type, value=value)
dacite.exceptions.WrongTypeError: wrong value type for field "test_value" - should be "bool" instead of value "JWrapper(<kayaku.backend.types.JWrapper object at 0x000001F646D4B070>, value=True, __orig_class__=kayaku.backend.types.JWrapper[bool], json_before=[WhiteSpace(' ')], json_after=[])" of type "JWrapper"
To Reproduce
Code to reproduce the behavior:
if __name__ == "__main__":
import kayaku
kayaku.initialize({"{**}": "./test/{**}"})
@kayaku.config("test")
class TestConfig:
test_value: bool = True
kayaku.create(TestConfig)
kayaku.bootstrap()
kayaku.save_all()
Steps to reproduce the behavior:
./test/test.jsonc
and ./test/test.schema.json
with the correct valueExpected behavior
TestConfig
should be properly read from file.
Enviroment
[tool.poetry.dependencies]
python = "^3.10"
kayaku = "0.5.0rc3"
Additional Content
Tested with more models, seems like only the one with bool
property would raise this exception.
if __name__ == "__main__":
import kayaku
kayaku.initialize({"{**}": "./test/{**}"})
@kayaku.config("test.str")
class TestStrConfig:
test_value: str = "test"
@kayaku.config("test.int")
class TestIntConfig:
test_value: int = 0
@kayaku.config("test.bool")
class TestBoolConfig:
test_value: bool = True
kayaku.create(TestStrConfig)
kayaku.create(TestIntConfig)
kayaku.create(TestBoolConfig)
kayaku.bootstrap()
kayaku.save_all()
鉴于 schema generator 已经换成自己写的了,所以动态更新是完全可能的
这将解决某些模块初始化就需要配置的问题
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.