I have null-ls setup with nvim and have a mypy diagnostic in my sources that I run on save
null_ls.builtins.diagnostics.mypy.with({
method = null_ls.methods.DIAGNOSTICS_ON_SAVE}),
Run Code Online (Sandbox Code Playgroud)
But as soon as I do, for example, nvim main.py, I get this error
[null-ls] failed to run generator: ...t/null-ls.nvim/lua/null-ls/helpers/generat
or_factory.lua:218: error in generator output: mypy: can't read file '/Users/me/main.py': No such file or directory
Run Code Online (Sandbox Code Playgroud)
The error disappears if I save the file and go back inside it.
Is the diagnostic running as soon as I open …
我在 SQLAlchemy 中遇到循环导入问题。
我有两个文件 foo.py 和 bar.py。foo.py 定义了一个 SQLAlchemy 类 Foo,bar.py 定义了一个类 Bar。
Foo 和 Bar 都是彼此的外键,因此我将它们相互映射Mapped["..."]以获得类型安全,但这意味着我还需要导入实际的类。
这会导致循环导入错误。
处理这个问题的最佳方法是什么?在 SQLAlchemy 中处理循环导入的一般最佳实践有哪些?如果您双向使用关系,在这种情况下就不能保证类型安全吗?
# foo.py
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
from .bar import Bar
class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
bar_id = Column(Integer, ForeignKey('bar.id'))
bar: Mapped["Bar"] = relationship('Bar')
# bar.py
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
from .foo import Foo
class Bar(Base):
__tablename__ = 'bar'
id = Column(Integer, …Run Code Online (Sandbox Code Playgroud)