pyright 1.1.403 started reporting "is not a known attribute of module"
Updated from 1.1.402 to 1.1.403 and started seeing error: "CLIENT" is not a known attribute of module ".constants". In pymysql, the CLIENT constants are defined in pymysql/constants/CLIENT.py. I expect no error.
Reproduction repository: https://github.com/mickvangelderen/pyright-issue-10690
main.py
import pymysql.constants.CLIENT
def main():
print(f"MULTI_STATEMENTS: {pymysql.constants.CLIENT.MULTI_STATEMENTS}")
if __name__ == "__main__":
main()
pyproject.toml
[project]
name = "pyright-403-pymysql"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"pymysql>=1.1.1",
]
[dependency-groups]
dev = [
"pyright>=1.1.403",
]
uv run pyright
/home/mick/projects/pyright-403-pymysql/main.py
/home/mick/projects/pyright-403-pymysql/main.py:4:50 - error: "CLIENT" is not a known attribute of module ".constants" (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations
I can confirm that I see the same bug. Downgrading to pyright==1.1.402 addresses it for me.
(In my case I also see it with pymysql, although with the ER member of constants rather than CLIENT. But the pattern is the same.)
The type information for pymysql comes from typeshed. Pyright 1.1.403 includes updated versions of the typeshed stubs, which explains why you are seeing a difference in behavior. If you think that the typeshed stubs are incorrect, please file a bug report or a PR with the typeshed project. I regularly pick up new versions of the typeshed stubs, so if it is modified there, a future version of pyright (and all other static typing tools that rely on typeshed) will automatically receive the fix.
I'm going to close this issue since this isn't a pyright bug.
Looking at this closer, it looks like this may be a bug in pyright after all. There haven't been any changes to pyright in the import handling recently, but it looks like there was a long-standing latent bug that is exposed by a recent change made to the pymysql stubs.
One thing to note is that currently the PyMySQL stubs just use from . import constants instead of from . import constants as constants. We're changing that, although that still doesn't with pyright. On the other hand, constants is mentioned in __all__, so both variants should work according to the typing spec.