mirror of
				https://github.com/nonebot/nonebot2.git
				synced 2025-10-31 15:06:42 +00:00 
			
		
		
		
	✨ support dot notation for driver config
This commit is contained in:
		| @@ -199,8 +199,12 @@ def init(*, _env_file: Optional[str] = None, **kwargs): | |||||||
|         logger.opt(colors=True).debug( |         logger.opt(colors=True).debug( | ||||||
|             f"Loaded <y><b>Config</b></y>: {escape_tag(str(config.dict()))}") |             f"Loaded <y><b>Config</b></y>: {escape_tag(str(config.dict()))}") | ||||||
|  |  | ||||||
|         DriverClass: Type[Driver] = getattr( |         modulename, _, cls = config.driver.partition(":") | ||||||
|             importlib.import_module(config.driver), "Driver") |         module = importlib.import_module(modulename) | ||||||
|  |         instance = module | ||||||
|  |         for attr_str in (cls or "Driver").split("."): | ||||||
|  |             instance = getattr(instance, attr_str) | ||||||
|  |         DriverClass: Type[Driver] = instance  # type: ignore | ||||||
|         _driver = DriverClass(env, config) |         _driver = DriverClass(env, config) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -144,6 +144,8 @@ class Config(BaseConfig): | |||||||
|     :说明: |     :说明: | ||||||
|  |  | ||||||
|       NoneBot 运行所使用的 ``Driver`` 。继承自 ``nonebot.driver.BaseDriver`` 。 |       NoneBot 运行所使用的 ``Driver`` 。继承自 ``nonebot.driver.BaseDriver`` 。 | ||||||
|  |  | ||||||
|  |       配置格式为 ``<module>[:<class>]``,默认类名为 ``Driver``。 | ||||||
|     """ |     """ | ||||||
|     host: IPvAnyAddress = IPv4Address("127.0.0.1")  # type: ignore |     host: IPvAnyAddress = IPv4Address("127.0.0.1")  # type: ignore | ||||||
|     """ |     """ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user