Skip to content

--verifytypes sometimes reports imported symbol as partially unknown, despite --ignoreexternal #11196

@MarcoGorelli

Description

@MarcoGorelli

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:

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:

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

$ pyright --version
pyright 1.1.407

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions