V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
NickLuan
V2EX  ›  Python

flask 中使用 sqlalchemy 在 pycharm 有语法提示插件吗

  •  
  •   NickLuan · 36 天前 · 940 次点击
    这是一个创建于 36 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如 User.query.filter_by()在 by 里面写关键字传参的时候,现在没有 User 模型的属性提示,很不方便。

    10 条回复    2024-03-25 20:07:40 +08:00
    IurNusRay
        1
    IurNusRay  
       36 天前
    用 filter 语法吧 User.query.filter(User.id == xxx)
    fgwmlhdkkkw
        2
    fgwmlhdkkkw  
       36 天前 via Android
    你可以包装一个函数,然后自己把类型补上
    NickLuan
        3
    NickLuan  
    OP
       36 天前
    @IurNusRay 有用到这种,就是略显啰嗦点
    NickLuan
        4
    NickLuan  
    OP
       36 天前
    @fgwmlhdkkkw 怎么操作老哥,,伪代码?
    fgwmlhdkkkw
        5
    fgwmlhdkkkw  
       36 天前 via Android
    python 也有泛型,你搜下 python typing
    fgwmlhdkkkw
        6
    fgwmlhdkkkw  
       36 天前
    @fgwmlhdkkkw #5 甚至可以只写一个 pyi 文件,完全没有运行时开销
    FYFX
        7
    FYFX  
       36 天前
    做不到吧,点进去看了一下 filter_by(self,**kwargs:Any)->Self ,Any 怎么都不行吧,再说 python 3.12 才支持用 TypeDict 给**kwargs 标注类型,你这而且你这种还需要传泛型参数
    Latin
        8
    Latin  
       33 天前
    尝试用参数输入和 sqlalchemy 都使用有 pydantic 集成的包
    pengdachxx
        9
    pengdachxx  
       33 天前
    这个用 typing 应该也解决不了
    NickLuan
        10
    NickLuan  
    OP
       33 天前
    @Latin 好像不行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1570 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 16:47 · PVG 00:47 · LAX 09:47 · JFK 12:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.