Search code examples
pythonsqlalchemysyntax-errorpyright

Pyright shows an error when converting column(int) to int


I can not assign a variable without adding # type:ignore || Used for pyright (Autocomplete) or it giving me an error. Error: [Pyright reportGeneralTypeIssues] [E] Argument of type "Column" cannot be assigned to parameter "id" of type "int" in function "__init__"   "Column" is incompatible with "int" (Im using SQLAlchemy btw)


Solution

  • When your extension doesn't work fine with some variable types in the program, you can use # type: ignore.

    It will work only in its scope, so...

    # type: ignore
    print(1 + 'x') # -> This won't throw errors
    
    def foo():
      return 2 + "!" # -> Neither this one will throw errors!
    
    print(foo())
    

    Instead...

    def foo():
      # type: ignore
      return 2 + "!" # -> This one won't throw errors
    
    print(foo())
    print(1 + 'x') # -> This one will throw an error!
    

    Working only in its scope, # type: ignore will have effect on the entire script if put in the first lines of the program, in the global scope.