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

Unexpected keyword argument #40

Closed
mehdigmira opened this issue Dec 6, 2018 · 6 comments
Closed

Unexpected keyword argument #40

mehdigmira opened this issue Dec 6, 2018 · 6 comments

Comments

@mehdigmira
Copy link
Contributor

Hello,
With the latest release of mypy and the master branch of sqlalchemy-stubs, this code causes mypy to raise a "error: Unexpected keyword argument "name" for "User""
Is there smth I can do to avoid these errors ?

from sqlalchemy import CheckConstraint, Column, Integer, String
from sqlalchemy.ext.declarative import as_declarative

@as_declarative()
class Base:
    pass


class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)


user = User(name="xx")
@ilevkivskyi
Copy link
Contributor

Duplicate of #5

(I have this working locally, but it requires more polish before publishing.)

@mehdigmira
Copy link
Contributor Author

Is there a workaround ?
I've tried the version below. I no longer have the error, but then mypy doesn' log errors he should be logging.

from typing import Any

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


Base = declarative_base()  # type: Any


class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)


class Address(Base):
    __tablename__ = 'addresses'
    id = Column(Integer, primary_key=True)
    name = Column(String)


def f() -> Address:
    user = User(name="xx")
    return user  # mypy should log an error here but doesn't

@mehdigmira
Copy link
Contributor Author

@ilevkivskyi Can I have ave some feedback on this if you have some time ?

@ilevkivskyi
Copy link
Contributor

There is no way to have no false positives and no false negatives before the plugin is ready. You can use @as_declarative instead however.

@mehdigmira
Copy link
Contributor Author

But then I have a ton of ""error: Unexpected keyword argument "name" for "User"" errors. It would require me an hour of "type: ignore" to silence them ^^.
I guess The only way is to wait for #5 to be resolved.

@ilevkivskyi
Copy link
Contributor

@as_declarative
class Base:
    def __init__(self, *args, **kwargs) -> None: ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants