V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Mar 22, 2024 · 2494 views
    This topic created in 771 days ago, the information mentioned may be changed or developed.

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

    10 replies    2024-03-25 20:07:40 +08:00
    IurNusRay
        1
    IurNusRay  
       Mar 22, 2024
    用 filter 语法吧 User.query.filter(User.id == xxx)
    fgwmlhdkkkw
        2
    fgwmlhdkkkw  
       Mar 22, 2024 via Android
    你可以包装一个函数,然后自己把类型补上
    NickLuan
        3
    NickLuan  
    OP
       Mar 22, 2024
    @IurNusRay 有用到这种,就是略显啰嗦点
    NickLuan
        4
    NickLuan  
    OP
       Mar 22, 2024
    @fgwmlhdkkkw 怎么操作老哥,,伪代码?
    fgwmlhdkkkw
        5
    fgwmlhdkkkw  
       Mar 22, 2024 via Android
    python 也有泛型,你搜下 python typing
    fgwmlhdkkkw
        6
    fgwmlhdkkkw  
       Mar 22, 2024
    @fgwmlhdkkkw #5 甚至可以只写一个 pyi 文件,完全没有运行时开销
    FYFX
        7
    FYFX  
       Mar 22, 2024
    做不到吧,点进去看了一下 filter_by(self,**kwargs:Any)->Self ,Any 怎么都不行吧,再说 python 3.12 才支持用 TypeDict 给**kwargs 标注类型,你这而且你这种还需要传泛型参数
    Latin
        8
    Latin  
       Mar 25, 2024
    尝试用参数输入和 sqlalchemy 都使用有 pydantic 集成的包
    pengdachxx
        9
    pengdachxx  
       Mar 25, 2024
    这个用 typing 应该也解决不了
    NickLuan
        10
    NickLuan  
    OP
       Mar 25, 2024
    @Latin 好像不行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2521 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 03:00 · PVG 11:00 · LAX 20:00 · JFK 23:00
    ♥ Do have faith in what you're doing.