![](/img/trans.png)
[英]How to typehint custom and overridden Managers in an Abstract Class using django-stubs?
我們正在嘗試將類型提示添加到我們的 django (3.2) 項目中。 我們正在使用 django-stubs (1.12.0)。 我們有一個帶有自定義BaseManager的AbstractBaseModel ,我們將其用於幾乎所有其他 model。在某些情況下,我們還擴展了自定義管理器。 例子 ...
[英]How to typehint custom and overridden Managers in an Abstract Class using django-stubs?
我們正在嘗試將類型提示添加到我們的 django (3.2) 項目中。 我們正在使用 django-stubs (1.12.0)。 我們有一個帶有自定義BaseManager的AbstractBaseModel ,我們將其用於幾乎所有其他 model。在某些情況下,我們還擴展了自定義管理器。 例子 ...
[英]Django: typehinting backward / related_name / ForeignKey relationships
假設我們有以下模型: 如果我在其他 class 的某個地方使用它: 然后mypy抱怨: 我怎樣才能讓 mypy 在這里開心? ...
[英]Mypy complaining about Name "Optional" is not defined without the use of Optional
我最近開始使用 mypy,並且遇到了一些我一生都無法解決的奇怪問題。 我正在使用 mypy 0.950、django-stubs 1.11.0、django 4.0.5 和 python 3.10.2。 通過命令行運行 mypy 會返回: 然而, project/suppliers/mode ...
[英]How to provide a source directory in the [tool.django-stubs] directive of a pyproject.tom file?
我在我的 django 項目中使用src目錄作為根源目錄。 我正在嘗試使用 mypy 和 django-stubs 對那些 django 項目執行預提交操作。 是在 pyproject.toml 中比源根目錄在src/中的一種方式嗎? 現在,我有:pre-commit run --all ... ...
[英]Type Hint for Django model with annotated field
假設我有以下 Django 型號: 我有一個 function 來獲取每個工具箱的所有小工具。 參數類型提示來自這個 SO 答案: 這里的想法是要求這個 function 的用戶使用prefetch_related()預取這個small_tools字段,以減少 db hits 的數量並加速代碼: 這 ...
[英]django-stubs: Missing type parameters for generic type "ModelSerializer"
我有 現在我運行 mypy 我得到 ...
[英]django, mypy : queryset, choices. error: Incompatible types
我們有: 在模型.py 在 serializers.py 中 當我通過 mypy 檢查它時: resources/serializers.py:67:錯誤:賦值中的類型不兼容(表達式的類型為“Union [Any, object]”,變量的類型為“int”) 如果在 serializers.py ...
[英]Mypy linting in VSCode Errors out with “Error constructing plugin instance of NewSemanalDRFPlugin”
嘗試在 VSCode 中運行 Mypy linter,總是在 output 中遇到相同的錯誤... Django項目的根目錄和工作區目錄不同。 mypy==0.770 mypy擴展==0.4.3 django-stubs==1.5.0 djangorestframework-stubs= ...
[英]request.user returning abstract user (django-stubs)
我正在嘗試輸入以下內容: 其中CustomUser是我在settings.py中定義的自定義用戶 model 。 我的 IDE 抱怨Expected type 'CustomUser', got 'AbstractBaseUser' instead 。 查看文檔,它說self.request.us ...
[英]Django stubs interrupt Pycharm autocompete
我有一個帶有多個模型的 django 應用程序。 這是我過濾對象時的自動完成功能 然后我為 MyPy 安裝 django-stubs 現在我的自動完成看起來像這樣 當我刪除 django-stubs 時自動完成效果很好,就像第一張圖片一樣 那么,有沒有辦法將 django-stub ...