Giter Site home page Giter Site logo

Comments (6)

erictraut avatar erictraut commented on June 15, 2024 1

@Apakottur, you asked whether this was a bug in the sqlalchemy stubs or in pyright. It appears to be a bit of both. I recommend filing a separate bug for the stubs issue.

from pyright.

erictraut avatar erictraut commented on June 15, 2024

Here's a simplified code sample:

from datetime import timedelta
from sqlalchemy.sql.functions import current_date

def func(a: current_date, b: timedelta):
    reveal_type(a.__add__) # Appears not to bind correctly
    a.__add__(b)

    return a + b

from pyright.

Azureblade3808 avatar Azureblade3808 commented on June 15, 2024

It seems that there is a missing overload in SQLAlchemy.

For sqlalchemy.sql.elements.SQLCoreOperations, its __add__ method is declared as such --

        @overload
        def __add__(
            self: _SQO[_NMT],
            other: Any,
        ) -> ColumnElement[_NMT]: ...

        @overload
        def __add__(
            self: _SQO[str],
            other: Any,
        ) -> ColumnElement[str]: ...

        def __add__(self, other: Any) -> ColumnElement[Any]: ...

, whereas _SQO is an alias of SQLCoreOperations and _NMT is a type variable with a bound of float, int or Decimal. We can see that type of self in overloads doesn't cover everything including SQLCoreOperations[datetime.datetime] in the sample.

If the code above is modified with an additional overload --

        @overload
        def __add__(
            self: _SQO[_NMT],
            other: Any,
        ) -> ColumnElement[_NMT]: ...

        @overload
        def __add__(
            self: _SQO[str],
            other: Any,
        ) -> ColumnElement[str]: ...

        # Added.
        @overload
        def __add__(self, other: Any) -> ColumnElement[Any]: ...

        def __add__(self, other: Any) -> ColumnElement[Any]: ...

, no error gets reported.

But I think the error message could be improved and the method should be uncallable in its current form.

from pyright.

erictraut avatar erictraut commented on June 15, 2024

Good analysis. I agree that the error message could be improved. I also think a.__add__ should generate an error since __add__ cannot be bound to a.

from pyright.

Apakottur avatar Apakottur commented on June 15, 2024

Opened a PR to fix the types, if it wont get accepted I'll open an issue.

from pyright.

erictraut avatar erictraut commented on June 15, 2024

This is addressed in pyright 1.1.360, which I just published.

from pyright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.