假设我有两个类Foo1并且Foo2实现了一个方法bar():
Foo1,bar()是一个正则方法Foo2,bar()是一个@classmethodclass Foo1:
def bar(self) -> None:
print("foo1.bar")
class Foo2:
@classmethod
def bar(cls) -> None:
print("Foo2.bar")
Run Code Online (Sandbox Code Playgroud)
现在假设我有一个函数,它接受“任何有bar()方法的东西”列表并调用它:
def foreach_foo_call_bar(foos):
for foo in foos:
foo.bar()
Run Code Online (Sandbox Code Playgroud)
在运行时调用此函数工作正常:
foreach_foo_call_bar([Foo1(), Foo2])
Run Code Online (Sandbox Code Playgroud)
因为两者都有Foo1()并且Foo2有一个bar()方法。
但是,如何正确地将类型提示添加到foreach_foo_call_bar()?
我尝试创建一个名为的PEP544 :ProtocolSupportsBar
class SupportsBar(Protocol):
def bar(self) -> None:
pass
Run Code Online (Sandbox Code Playgroud)
并像这样注释:
def foreach_foo_call_bar(foos: Iterable[SupportsBar]):
...
Run Code Online (Sandbox Code Playgroud)
但是 mypy 说:
List item 1 has …Run Code Online (Sandbox Code Playgroud) 该迁飞路线常见问题分开3箱子多种模式的:
我们正在使用 Maven 构建一个多模块 Spring Boot 4.5.9 项目。每个模块都是完全独立的,并且有自己的数据库模式。所有模式都驻留在一个数据库中,因此只有一个 Spring 数据源。
因为模块是独立的,我们想分别管理它们各自的模式迁移,所以上面的选项(3)是最合适的。
但是,我找不到按照 Flyway FAQ 建议的方式配置 Spring Boot 的 Flyway 集成的方法:
使用多个 Flyway 实例。每个实例管理自己的模式并引用自己的模式历史表。将每个架构的迁移放在不同的位置。
理想情况下,每个模块都有自己的db/migration文件夹,其中包含自己的迁移 SQL 脚本。每个模块脚本的版本应该独立于其他模块中的脚本版本,并且每个模块的迁移历史应该存储在该模块模式的表中。
如果我将迁移脚本放在每个模块的resources/db/migration文件夹中,flyway 会检测到它们,然后抱怨:
org.flywaydb.core.api.FlywayException: Found more than one migration with version 0
Run Code Online (Sandbox Code Playgroud)
有人知道如何完成所需的设置吗?
PS 所有这一切的最终目标是能够(有一天,当系统扩展时)将这些模块拉入单独的服务中,而无需经历地狱将数据库分解为多个部分。