Commit Graph

84 Commits

Author SHA1 Message Date
Federico Caselli 4699684387 fix failing typing test
fix failing test added in 4ac02007e0

Change-Id: If0c62fac8744caa98bd04f808ef381ffb04afd7f
2025-05-05 23:03:18 +02:00
Federico Caselli 4ac02007e0 add correct typing for row getitem
The overloads were broken in 8a4c275895

Change-Id: I3736b15e95ead28537e25169a54521e991f763da
2025-04-29 22:41:30 +02:00
Federico Caselli 571bb90932 Add pow operator support
Added support for the pow operator (``**``), with a default SQL
implementation of the ``POW()`` function.   On Oracle Database, PostgreSQL
and MSSQL it renders as ``POWER()``.   As part of this change, the operator
routes through a new first class ``func`` member :class:`_functions.pow`,
which renders on Oracle Database, PostgreSQL and MSSQL as ``POWER()``.

Fixes: #8579
Closes: #8580
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8580
Pull-request-sha: 041b2ef474

Change-Id: I371bd44ed3e58f2d55ef705aeec7d04710c97f23
2025-04-22 15:54:50 +00:00
Denis Laxalde 09c1d3ccac Type postgresql.aggregate_order_by()
Overloading of `__init__()` is needed, probably for the same reason as it is in `ReturnTypeFromArgs`.

Related to #6810.

Closes: #12463
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12463
Pull-request-sha: 701d979e20

Change-Id: I7e1bb4d2c48dfb3461725c7079aaa72c66f1dc03
2025-04-09 03:04:20 -04:00
Federico Caselli 5cc6a65c61 improve overloads applied to generic functions
try again to remove the overloads to the generic functionn
generator (like coalesce, array_agg, etc).
As of mypy 1.15 it still does now work, but a simpler version
is added in this change

Change-Id: I8b97ae00298ec6f6bf8580090e5defff71e1ceb0
2025-03-25 23:39:05 +01:00
Denis Laxalde 543acbd8d1 Type array_agg()
The return type of `array_agg()` is declared as a `Sequence[T]` where `T` is bound to the type of input argument.

This is implemented by making `array_agg()` inheriting from `ReturnTypeFromArgs` which provides appropriate overloads of `__init__()` to support this.

This usage of ReturnTypeFromArgs is a bit different from previous ones as the return type of the function is not exactly the same as that of its arguments, but a "collection" (a generic, namely a Sequence here) of the argument types.  Accordingly, we adjust the code of `tools/generate_sql_functions.py` to retrieve the "collection" type from 'fn_class' annotation and generate expected return type.

Also add a couple of hand-written typing tests for PostgreSQL.

Related to #6810

Closes: #12461
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12461
Pull-request-sha: ba27cbb863

Change-Id: I3fd538cc7092a0492c26970f0b825bf70ddb66cd
2025-03-24 22:22:35 +01:00
Denis Laxalde 500adfafcb Make ARRAY generic on the item_type
Now `Column(type_=ARRAY(Integer)` is inferred as `Column[Sequence[int]]` instead as `Column[Sequence[Any]]` previously. This only works with the `type_` argument to Column, but that's not new.

This follows from a suggestion at
https://github.com/sqlalchemy/sqlalchemy/pull/12386#issuecomment-2694056069.

Related to #6810.

Closes: #12443
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12443
Pull-request-sha: 2fff4e89cd

Change-Id: I87b828fd82d10fbf157141db3c31f0ec8149caad
2025-03-18 12:23:01 -04:00
Federico Caselli 1ebd8c525b remove deprecated features
Remove feature deprecates in 1.3 and before

Fixes: #12441
Change-Id: Ice3d35ec02988ce94cdeb9db41cb684db2fb5d8d
2025-03-18 09:17:07 -04:00
Denis Laxalde 75c8e112c9 Add type annotations to postgresql.array
Improved static typing for `postgresql.array()` by making the type parameter (the type of array's elements) inferred from the `clauses` and `type_` arguments while also ensuring they are consistent.

Also completed type annotations of `postgresql.ARRAY` following commit 0bf7e02afb and added type annotations for functions `postgresql.Any()` and `postgresql.All()`.

Finally, fixed shadowing `typing.Any` by the `Any()` function through aliasing as `typing_Any`.

Related to #6810

Closes: #12384
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12384
Pull-request-sha: 78eea29f1d

Change-Id: I5d35d15ec8ba4d58eeb9bf00abb710e2e585731f
2025-03-15 16:21:27 +01:00
Federico Caselli b2ee1df06b improve rowmapping key type
the accepted keys are also orm attributes, column elements, functions
etc, not only columns

Change-Id: I354de9b9668bc02b8b305a3c1f065744b28f8030
2025-02-26 20:32:09 +01:00
Mingyu Park fc44b5078b Support generic types for union and union_all
Support generic types for compound selects (:func:`_sql.union`,
:func:`_sql.union_all`, :meth:`_sql.Select.union`,
:meth:`_sql.Select.union_all`, etc) returning the type of the first select.

Fixes: #11922
Closes: #12320
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12320
Pull-request-sha: f914a19f72

Change-Id: I4fffa5d3fe93dd3a293b078360e326fea4207c5d
2025-02-12 21:00:27 +01:00
Mike Bayer 5c79e5ce2d typing fix: allow stmt.excluded for set_
Change-Id: I6f0af23fba8f5868282505438e6ca0a5af7e1bbe
2024-12-18 19:47:17 -05:00
Michael Bayer 3e5e806985 Merge "Removed support for Python 3.8 since it's EOL." into main 2024-11-06 23:55:51 +00:00
Federico Caselli 2adc79c077 Removed support for Python 3.8 since it's EOL.
Fixes: #12029
Change-Id: Ibb4efec9bab0225d03f6bf3fed661a3f2fc72cc7
2024-11-05 21:23:34 +01:00
Federico Caselli 732698427e Improve mutable typing.
References: #12046
Change-Id: If950f7e2090a0f637c2c28cf21a40dc345acc89a
2024-10-30 21:23:52 +01:00
Michael Bayer 89ea870661 Merge "use driver col names" into main 2024-07-05 14:10:40 +00:00
opkna f979aff468 Added valid types to server_onupdate (#11555)
* Added valid types to server_onupdate and mapped_column kwargs mypy tests
* Joined mapped_column test files
* Set _ServerOnUpdateArgument to _ServerDefaultArgument

Fixes: #11546
2024-07-04 22:13:10 +02:00
Mike Bayer b3105b7e3a use driver col names
Added new execution option
:paramref:`_engine.Connection.execution_options.driver_column_names`. This
option disables the "name normalize" step that takes place against the
DBAPI ``cursor.description`` for uppercase-default backends like Oracle,
and will cause the keys of a result set (e.g. named tuple names, dictionary
keys in :attr:`.Row._mapping`, etc.) to be exactly what was delivered in
cursor.description.   This is mostly useful for plain textual statements
using :func:`_sql.text` or :meth:`_engine.Connection.exec_driver_sql`.

Fixes: #10789
Change-Id: Ib647b25bb53492fa839af04dd032d9f061e630af
2024-07-04 10:50:19 -04:00
Mike Bayer 9b631dff45 add additional test cases re: #11371
Just want to make sure aliased() and with_polymorphic() still
work in the of_type() context here, since that's likely why we
had Any for this parameter in the first place

Change-Id: I0a2c4445bc3b91039b3446d31b4a02db28feaee7
2024-06-26 12:15:03 -04:00
Wouter Kayser 7d8dfa10df set type of type_of to be same as input argument
Fixes: #11371

Fixes the of_type method so that it does not return a class with unset generic.
See the original issue for a more detailed explanation.

Closes: #11416
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11416
Pull-request-sha: ed8d0edebb

Change-Id: I35637491d6d9c573825f6d13299712626dd521c5
2024-06-25 22:08:08 +02:00
Federico Caselli 57bba09659 Add missing function element methods
Added missing methods :meth:`_sql.FunctionFilter.within_group`
and :meth:`_sql.WithinGroup.filter`

Fixes: #11423
Change-Id: I4bafd9e3cab5883b28b2b997269df239739a2212
2024-05-30 22:17:48 +02:00
Michael Bayer 92732bb37a Merge "Updated typing for self_group()" into main 2024-05-05 15:43:08 +00:00
Mark Elliot ab6df37dad Add overload for ColumnCollection.get(col, default)
### Description
Fixes #11328 by adding an overload to ColumnCollection when a non-None default is provided.

### Checklist
This pull request is:

- [ ] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [x] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

Closes: #11329
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11329
Pull-request-sha: 32db849e0d

Change-Id: I8bef91c423fb7048ec8d4a7c99f70f0b1588c37a
2024-05-04 11:33:23 +02:00
Federico Caselli 7173b04778 Updated typing for self_group()
Fixes: #10939
Closes: #11037
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11037
Pull-request-sha: 3ebf4db506

Change-Id: I22218286b0dac7bafaaf6955557e25f99a6aefe1
2024-05-04 11:23:52 +02:00
Federico Caselli 60498e9185 Merge "disable col deduping inside of Bundle" into main 2024-05-04 08:10:51 +00:00
Michael Bayer 4c52f491d2 Merge "Improve typing to the count function." into main 2024-05-02 22:34:46 +00:00
Mike Bayer 7d6d7ef73a disable col deduping inside of Bundle
Fixed issue where attribute key names in :class:`_orm.Bundle` would not be
correct when using ORM enabled :class:`_sql.select` vs.
:class:`_orm.Query`, when the statement contained duplicate column names.

Fixed issue in typing for :class:`_orm.Bundle` where creating a nested
:class:`_orm.Bundle` structure were not allowed.

Fixes: #11347
Change-Id: I24b37c99f83068c668736caaaa06e69a6801ff50
2024-05-02 15:13:46 -04:00
Federico Caselli d85289b35e Fixing ci errors
Change-Id: Ia1e3a8748a36dd3fa013707eae5ee4f97013d71b
2024-04-27 13:39:27 +02:00
Yossi Rozantsev 18b5b8a5b4 Add missing overload to __add__
Add a missing `@overload` to the `__add__` operator.

### Description
The `__add__` function is missing an overload that handles the rest of the cases, similar to the one that `__sub__` has a few lines later in the same file.

This fix is taken from https://github.com/microsoft/pyright/issues/7743

### Checklist
This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #11307
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11307
Pull-request-sha: 961d87403a

Change-Id: I27784f79e8d4f8b7f09b17060186916c78cba0a3
2024-04-25 20:17:58 +00:00
Federico Caselli 980cfc5bdf Improve typing to the count function.
Improve typing to allow `'*'` and 1 in the count function.

Fixes: #11316
Change-Id: Iaafdb779b6baa70504154099f0b9554c612a9ffa
2024-04-25 19:42:58 +00:00
Federico Caselli 859dda8f0b Fix typing to support mypy 1.10
Change-Id: I77c0a04331a99c7be77c174721431a5601475dc3
2024-04-24 22:30:21 +02:00
Michael Bayer 483edf651f Merge "typing: annotate Exists.select() to return Select[bool]" into main 2024-04-12 15:49:18 +00:00
Francisco Del Roio 40fc02d93f Fix typing issue in MetaData.reflect() with asyncio.
Fixed typing regression caused by PR 🎫`11055` in version 2.0.29 that
attempted to add ``ParamSpec`` to the asyncio ``run_sync()`` methods, where
using :meth:`_asyncio.AsyncConnection.run_sync` with
meth:`_schema.MetaData.reflect` would fail on mypy due to a bug.
See https://github.com/python/mypy/issues/17093 for details.
Pull request courtesy of Francisco R. Del Roio

Fixes: #11200
Closes: #11201
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11201
Pull-request-sha: 49e10e0d2a

Change-Id: Ie2ebaebd1bc1ee1b865b78561cb6cb8937e85eca
2024-04-10 21:01:36 +02:00
wouter bolsterlee ceb9e021cd typing: annotate Exists.select() to return Select[bool]
Fixes: #11231

A query of the form:

``` sql
SELECT EXISTS (
    SELECT 1
    FROM ...
    WHERE ...
)
```

… returns a boolean.

Closes: #11233
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11233
Pull-request-sha: 1bec1cac73

Change-Id: I407a3bd9ed21a180c6c3ff02250aa0a9fbe502d7
2024-04-04 14:15:07 -04:00
Michael Bayer 0b3b1036a0 Merge "use a private return class for the "catch all" relationship" into main 2024-03-22 13:30:47 +00:00
Federico Caselli bf7289f9d4 A scalar subquery that returns bool is now correctly typed
Fixes: #10937
Change-Id: Iba4986be14fefd4210b727ddb7ae7e9291ab7f7f
2024-03-20 22:18:59 +01:00
Mike Bayer 674303456c use a private return class for the "catch all" relationship
Fixed Declarative issue where typing a relationship using
:class:`_orm.Relationship` rather than :class:`_orm.Mapped` would
inadvertently pull in the "dynamic" relationship loader strategy for that
attribute.

Fixes: #10611
Change-Id: Ie4421050b583827fdf96c27ae9d7fe7ca596e77e
2024-03-20 21:40:39 +01:00
Federico Caselli 34a974e509 fix mypy on python<3.10
Change-Id: Ice16ff3685f89c64607ef37a906e17c53a5324fd
2024-03-15 20:42:16 +01:00
Ethan Langevin 058e10f2b7 Make instrumented attribute covariant as well
<!-- Provide a general summary of your proposed changes in the Title field above -->

Allows mapped relationships to use covariant types which makes it possible to define methods that operate on relationships in a typesafe way

### Description

See: https://github.com/sqlalchemy/sqlalchemy/issues/11112 for a more in depth explanation.

Just changed the type parameter in `InstrumentedAttribute` from `_T` to `_T_co`.

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [ ] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [x] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #11113
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11113
Pull-request-sha: 3c100f2866

Change-Id: Iff715c24f1556d5604dcd33661a0ee7232b9404b
2024-03-12 23:14:56 +01:00
Federico Caselli 716189460f Merge "Fixes: #10933 typing in ColumnExpressionArgument" into main 2024-03-11 22:10:55 +00:00
Michael Bayer 46f1ff9fb9 Merge "Allow using AsyncEngine in compile" into main 2024-03-11 22:04:45 +00:00
Daniel Robert 3551c7b66a Fixes: #11083 (#11095) 2024-03-11 22:34:20 +01:00
Eugene Toder d2a743d0bc Allow using AsyncEngine in compile
This works, so only need to update the type annotation.

This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed

Closes: #11103
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11103
Pull-request-sha: ba9e61a390

Change-Id: I3d08b930a8cae0539bf9b436d5e806d8912cdee0
2024-03-11 21:42:01 +01:00
Francisco R. Del Roio 3eaff251bf Fixed typing issues with sync code runners
Fixed typing issue allowing asyncio ``run_sync()`` methods to correctly
type the parameters according to the callable that was passed, making use
of :pep:`612` ``ParamSpec`` variables.  Pull request courtesy Francisco R.
Del Roio.

Closes: #11055
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11055
Pull-request-sha: 712b4382b1

Change-Id: I94ec8bbb0688d6c6e1610f8f769abab550179c14
2024-03-11 17:06:41 +00:00
Tomasz Nowacki e4fa174583 Fixes: #10933 typing in ColumnExpressionArgument
### Description
Fixes: #10933 typing in ColumnExpressionArgument

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [ ] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [x] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #10959
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10959
Pull-request-sha: 6fed2cf1d1

Change-Id: I43420add824881e7cc0ec93e3c8b9a04d33e30df
2024-03-04 09:52:02 -05:00
Federico Caselli f0537442eb Add support for preserve_rowcount execution_option
Added new core execution option
paramref:`_engine.Connection.execution_options.preserve_rowcount`
to unconditionally save the ``rowcount`` attribute from the cursor in the
class:`_engine.Result` returned from an execution, regardless of the
statement being executed.
When this option is provided the correct value is also set when
an INSERT makes use of the "insertmanyvalues" mode, that may use
more than one actualy cursor execution.

Fixes: #10974
Change-Id: Icecef6b7539be9f0a1a02b9539864f5f163dcfbc
2024-03-03 17:58:12 -05:00
Jim Bosch 4006cb38e1 Fix typing generics in PostgreSQL range types.
Correctly type PostgreSQL RANGE and MULTIRANGE types as ``Range[T]``
and ``Sequence[Range[T]]``.
Introduced utility sequence ``MultiRange`` to allow better
interoperability of MULTIRANGE types.

Fixes #9736
Closes: #10625
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10625
Pull-request-sha: 2c17bc5f92

Change-Id: I4f91d0233b29fd8101e67bdd4cd0aa2524ab788a
2024-02-07 19:10:31 +01:00
Federico Caselli 9b153ff18f Update black to 24.1.1
Change-Id: Iadaea7b798d8e99302e1acb430dc7b758ca61137
2024-01-31 21:54:59 +01:00
Michael Bayer 8a4c275895 Merge "Add PEP 646 integration" into main 2024-01-24 15:42:11 +00:00
Yurii Karabas 00072000c5 Add PEP 646 integration
The :class:`.Row` object now no longer makes use of an intermediary
``Tuple`` in order to represent its individual element types; instead,
the individual element types are present directly, via new :pep:`646`
integration, now available in more recent versions of Mypy.  Mypy
1.7 or greater is now required for statements, results and rows
to be correctly typed.   Pull request courtesy Yurii Karabas.

Fixes: #10635
Closes: #10634
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10634
Pull-request-sha: 430785c8a0

Change-Id: Ibd0ae31a98b4ea69dcb89f970e640920b2be6c48
2024-01-22 19:49:05 +01:00