Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type is not callable error using SQLAlchemy's declarative_base #507

Closed
nirn opened this issue Oct 20, 2020 · 6 comments
Closed

Type is not callable error using SQLAlchemy's declarative_base #507

nirn opened this issue Oct 20, 2020 · 6 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@nirn
Copy link

nirn commented Oct 20, 2020

Environment data

  • Language Server version: 2020.10.1
  • OS and version: Windows 10, 2004
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.3

Expected behaviour

No errors.

Actual behaviour

Two errors appear:

"User" has type "Type[User]" and is not callable
  Type "Type[User]" is not callable Pylance (reportGeneralTypeIssues)
Expected no arguments to "User" constructor Pylance (reportGeneralTypeIssues)

Code Snippet / Additional information

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class User(Base):
    id = Column(Integer, primary_key=True, index=True)
    username = Column(String(255), unique=True, index=True)


user = User(id=1, username='test')

image

SQLAlchemy's declarative_base should use this _declarative_constructor by default, which allows initialization from kwargs.
There are no errors for the same snippet using standalone Pyright (1.1.80) without Pylance.

@erictraut
Copy link
Contributor

Thanks for the bug report. SqlAlchemy is using a custom metaclass that provides non-standard behaviors for a constructor. I've changed the logic in pylance to avoid emitting this particular error when a class is instantiated from a custom metaclass, so you won't see this false positive in the future.

This fix will be in the next release of pylance.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Oct 20, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.10.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020102-21-october-2020

@jakebailey
Copy link
Member

This issue has been fixed in version 2020.10.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020103-28-october-2020

@aaronkavlie-wf
Copy link

I still get the "Expected no arguments" bug on SQLAlchemy model class initialization.

(running Pylance 2020.11.1)

@erictraut
Copy link
Contributor

I just re-verified that the code sample above does not result in any errors. If your code differs from the above, please post a simple example that exhibits the problem.

@aaronkavlie-wf
Copy link

I just re-verified that the code sample above does not result in any errors. If your code differs from the above, please post a simple example that exhibits the problem.

Sorry about the trouble Eric, the errors are gone now. I think my workspace just wasn't pointed at my virtualenv's Python interpreter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

4 participants