Comments (6)
@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.
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.
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.
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.
Opened a PR to fix the types, if it wont get accepted I'll open an issue.
from pyright.
This is addressed in pyright 1.1.360, which I just published.
from pyright.
Related Issues (20)
- Pyright ignores configuration from custom toml files HOT 5
- Typeguard is not None with list[int|None] and index subscript not working HOT 3
- Issues accessing `enum.nonmember` from another `nonmember` HOT 3
- python HOT 1
- obj.get("CONST") does not imply "CONST" in obj for reportTypedDictNotRequiredAccess HOT 1
- Version-aware `reportShadowedImports` HOT 3
- StrEnum `value` property type regression HOT 2
- `def __init__(self: Self)` causes `reportInvalidTypeVarUse` HOT 1
- reportOverlappingOverload false positive: variadic tuple unpacking HOT 2
- Generic types are reused / only bound once HOT 3
- Introduce `reportUnnecessaryTypeIs` rule HOT 3
- Support different type for class variable and instance variable HOT 3
- Different inferred type `t = tuple(); list(t)` and `list(tuple())` HOT 1
- Type hinting for tuples HOT 4
- `str` is considered incompatible with `Annotated[str]` HOT 1
- `__doc__` inside class body has type `str | None` even though doc-string is defined HOT 1
- `reportIncompatibleMethodOverride` false positive on extra overloads in subclass HOT 1
- Overloaded decorators break type inference for self-referential methods HOT 3
- Changed TypeIs behavior in 1.1.361 to 1.1.364 HOT 2
- Feature Request: Insert all arguments of a function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyright.