Commit Graph

12 Commits

Author SHA1 Message Date
Rebecca Chen 0ab0d0c980 Change typing tests to use assert_type instead of reveal_type
Closes: #12922
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12922
Pull-request-sha: 580f663816

Change-Id: I9f3bdb4c105971f53fa10ed8a934356203ddb080
2025-10-18 11:23: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
Federico Caselli d539bc3a0f update the format_docs_code to also work on python files
Change-Id: I0a6c9610b3fd85365ed4c2c199e3cad87ee64022
2024-11-30 21:10:21 +01:00
Federico Caselli 73344fd0d3 Fix select.with_only_columns type hints
Fixes: #11782
Change-Id: Idce218a9730986d3ca70547c83aa1c0f8b5ee5b2
2024-08-28 21:52:30 +02: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
Mike Bayer cc26af00e7 allow literals for function arguments
* Fixed the argument types passed to functions so that literal expressions
like strings and ints are again interpreted correctly (🎫`10818`)

this includes a reformatting of the changelog message from #10801
to read as a general "fixed regressions" list.

Fixes: #10818
Change-Id: I65ad86e096241863e833608d45f0bdb6069f5896
2024-01-02 19:07:34 -05:00
Mike Bayer 045732a738 fully type functions.py
Completed pep-484 typing for the ``sqlalchemy.sql.functions`` module.
:func:`_sql.select` constructs made against ``func`` elements should now
have filled-in return types.

References: #6810
Change-Id: I5121583c9c5b6f7151f811348c7a281c446cf0b8
2023-11-25 09:46:22 -05:00
Federico Caselli c3acf8a5d2 Improve typing tests
Extract a fixture to run mypy on files
Move the plain files to test/typing
Move test files from stubs repository
Transform the fixture module in a package

Change-Id: I23acaecb84e7c4b9010259d44395dc1df83a9385
2023-06-27 23:50:25 +02:00
Federico Caselli 058c230cea Update black to v23.3.0 and flake8 to v6
This change could be added to .git-blame-ignore-revs

Change-Id: I7ba10052b26bc3c178d23fb50a1123d0aae965ca
2023-05-30 21:44:26 +02:00
Federico Caselli c39dc697c1 Add missing overload to Numeric
Added missing init overload to :class:`_sql.Numeric` to allow
type checkers to properly resolve the type var given the
``asdecimal`` parameter.

this fortunately fixes a glitch in the generate_sql_functions script
also

Fixes: #9391
Change-Id: I9cecc40c52711489e9dbe663f110c3b81c7285e4
2023-03-03 10:40:17 -05:00
Mike Bayer 6499098e36 generate stubs for func known functions
Added typing for the built-in generic functions that are available from the
:data:`_sql.func` namespace, which accept a particular set of arguments and
return a particular type, such as for :class:`_sql.count`,
:class:`_sql.current_timestamp`, etc.

Fixes: #9129
Change-Id: I1a2e0dcca3048c77e84dc786843a7df05c457dfa
2023-01-23 11:17:38 -05:00