python / python/mypy

Name "db.Model" is not defined in Mypy but is defined in SQLAlchemy function from flask_sqlalchemy package in VSCode

Open
#17,918 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

(A clear and concise description of what the bug is.)

To Reproduce

from flask import Flask, render_template, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import math

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///users.db"
db = SQLAlchemy(app)


class User(db.Model):

Expected Behavior
No errors because db.Model is in the SQLAlchemy class of flask_sqlalchemy, so the official Python extensions shows (variable) db: SQLAlchemy when I highlight the error squiggle in VSCode.

Actual Behavior
Name "db.Model" is not defined

Your Environment

  • Mypy version used: 1.11.2
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Python reproduction using mypy 1.11.2 and Python 3.9, then compare mypy's handling of db.Model with VSCode's inferred SQLAlchemy type. The issue names no mypy source file or test, so the first task is locating the analysis path for flask_sqlalchemy's SQLAlchemy(app) and determining the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python, sqlalchemy, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.