`--verifytypes` sometimes reports imported symbol as partially unknown, despite `--ignoreexternal`
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
If I write an annotation using sqlalchemy and then using `--verifytypes` with `--ignoreexternal`, the sqlalchemy symbol may still end up being reported as unknown, depending on how the annotation was written
**Code or Screenshots**
My file `foo/__init__.py`:
```python
class NDFrame:
def to_sql_1(
self,
con,
) -> None:
return None
def to_sql_2(
self,
con,
) -> None:
return None
```
My file `foo/__init__.pyi`:
```py
from sqlalchemy.engine import Connectable
import sqlalchemy.engine
class NDFrame:
def to_sql_1(
self,
con: str | Connectable,
) -> None: ...
def to_sql_2(
self,
con: str | sqlalchemy.engine.Connectable,
) -> None: ...
```
The annotations should in theory be identical, as far as I understand.
However, if I run `pyright --verifytypes foo --ignoreexternal`, I get:
```
Module name: "foo"
Package directory: "/home/marcogorelli/tmp-repo/foo"
Module directory: "/home/marcogorelli/tmp-repo/foo"
Path of py.typed file: "/home/marcogorelli/tmp-repo/foo/py.typed"
Public modules: 1
foo
Symbols used in public interface:
foo.NDFrame.to_sql_2
/home/marcogorelli/tmp-repo/foo/__init__.pyi:11:9 - error: Type of parameter "con" is partially unknown
Parameter type is "str | Unknown"
Symbols exported by "foo": 3
With known type: 1
With ambiguous type: 0
With unknown type: 2
(Ignoring unknown types imported from other packages)
Other symbols referenced but not exported by "foo": 0
With known type: 0
With ambiguous type: 0
With unknown type: 0
Symbols without documentation:
Functions without docstring: 2
Functions without default param: 0
Classes without docstring: 1
Type completeness score: 33.3%
Completed in -0.202sec
```
Note how:
- `con` is treated fine (ignored by `--ignoreexternal`) in `to_sql_1`
- but not in `to_sql_2` where it shows `Type of parameter "con" is partially unknown`
**VS Code extension or command-line**
```console
$ pyright --version
pyright 1.1.407
```
Contributor guide
Research direction
Reproduce the report with foo/__init__.py and foo/__init__.pyi using `pyright --verifytypes foo --ignoreexternal`. Compare the handling of `Connectable` in the two annotations; done means equivalent annotations receive the same treatment and the qualified form no longer produces a partially unknown parameter type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100