summaryrefslogtreecommitdiff
path: root/test/ext/mypy
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve typings of execution optionsFederico Caselli2022-11-022-0/+98
| | | | | Fixes: #8605 Change-Id: I4aec83b9f321462427c3f4ac941c3b272255c088
* Improve typing of DeclarativeBaseFederico Caselli2022-10-192-1/+11
| | | | | | | Also allow mapped columns inside indexes, unique cosntraints, primary key constriant Fixes: #8645 Change-Id: If37ab85ead0fbd1125cd6329c2f01a031777b081
* rename MappedCollection and relatedMike Bayer2022-10-112-3/+48
| | | | | | | | | | | | | | | | | | For consistency with the prominent ORM concept :class:`_orm.Mapped`, the names of the dictionary-oriented collections, :func:`_orm.attribute_mapped_collection`, :func:`_orm.column_mapped_collection`, and :class:`_orm.MappedCollection`, are changed to :func:`_orm.attribute_keyed_dict`, :func:`_orm.column_keyed_dict` and :class:`_orm.KeyFuncDict`, using the phrase "dict" to minimize any confusion against the term "mapped". The old names will remain indefinitely with no schedule for removal. Docs here are also updated for typing as we can type these collections as ``Mapped[dict[str, cls]]``, don't need KeyFuncDict / MappedCollection for these Fixes: #8608 Change-Id: Ib5cf63e0aef1c389e023a75e454bb21f9d779b54
* implement write-only colletions, typing for dynamicMike Bayer2022-10-062-0/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For 2.0, we provide a truly "larger than memory collection" implementation, a write-only collection that will never under any circumstances implicitly load the entire collection, even during flush. This is essentially a much more "strict" version of the "dynamic" loader, which in fact has a lot of scenarios that it loads the full backing collection into memory, mostly defeating its purpose. Typing constructs are added that support both the new feature WriteOnlyMapping as well as the legacy feature DynamicMapping. These have been integrated with "annotion based mapping" so that relationship() uses these annotations to configure the loader strategy as well. additional changes: * the docs triggered a conflict in hybrid's "transformers" section, this section is hard-coded to Query using a pattern that doesnt seem to have any use and isn't part of the current select() interface, so just removed this section * As the docs for WriteOnlyMapping are very long, collections.rst is broken up into two pages now. Fixes: #6229 Fixes: #7123 Change-Id: I6929f3da6e441cad92285e7309030a9bac4e429d
* reorganize Mapped[] super outside of MapperPropertyMike Bayer2022-10-052-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | We made all the MapperProperty classes a subclass of Mapped[] to allow declarative mappings to name Mapped[] on the left side. this was cheating a bit because MapperProperty is not actually a descriptor, and the mapping process replaces the object with InstrumentedAttribute at mapping time, which is the actual Mapped[] descriptor. But now in I6929f3da6e441cad92285e7309030a9bac4e429d we are considering making the "cheating" a little more extensive by putting DynamicMapped / WriteOnlyMapped in Relationship's hierarchy, which need a flat out "type: ignore" to work. Instead of pushing more cheats into the core classes, move out the "Declarative"-facing versions of these classes to be typing only: Relationship, Composite, Synonym, and MappedSQLExpression added for ColumnProperty. Keep the internals expressed on the old names, RelationshipProperty, CompositeProperty, SynonymProperty, ColumnProprerty, which will remain "pure" with fully correct typing. then have the typing only endpoints be where the "cheating" and "type: ignores" have to happen, so that these are more or less slightly better forms of "Any". Change-Id: Ied7cc11196c9204da6851f49593d1b1fd2ef8ad8
* add typing for sqlalchemy.orm.validatesMike Bayer2022-09-251-0/+20
| | | | | Fixes: #8577 Change-Id: Iede1c956078960fb866da45f1ac6aa43842516bc
* fix lambda styles for relationshipMike Bayer2022-07-251-0/+19
| | | | Change-Id: I810fafc4cbcf0ac9b1f0de764130c81c56367a16
* set up Literal for synchronize_sessionMike Bayer2022-07-231-0/+19
| | | | | Fixes: #8280 Change-Id: I59bc6cc0483375f79e17952188e0c2cde926502c
* remove mypy_path workaround and ensure messages receivedMike Bayer2022-07-234-19/+13
| | | | | | Fixes: #8281 Change-Id: Ice47880ba7924daff68aef6b1791f3c66849f550
* add contextmanager typing, open run_sync typingMike Bayer2022-07-181-0/+14
| | | | | | | | | | | | was missing AsyncConnection type for the async context manager. fixing that revealed that _SyncConnectionCallable and _SyncSessionCallable protocols are infeasible because the given callable can have a lot of different signatures that are compatible. Change-Id: I559aa3dd88a902d0e7681c52223bb4bc0890adc1
* update ORM declarative docs for new featuresMike Bayer2022-07-162-3/+27
| | | | | | | I screwed up a rebase or something so this was temporarily in Ic51a12de3358f3a451bd7cf3542b375569499fc1 Change-Id: I847ee1336381221c0112b67854df022edf596b25
* add some typing tests for declared_attr, mixins, decl baseMike Bayer2022-07-092-0/+107
| | | | | | | to make typing easier, looking at using getattr on table.c rather than getitem for now Change-Id: I7946885071d0b0ddfc06be009f033495f9906de5
* Support lambda expression in mypy pluginCyril Chapellier2022-07-021-0/+11
| | | | | | | Avoid `error: INTERNAL ERROR` when the default is a lambda Fixes: #8196 Change-Id: I7346c693519b024c56156db6f4ffc9a45bb748d3
* typing adjustments for compositesMike Bayer2022-06-141-0/+51
| | | | | | | | | * if dataclass isn't used, columns have to be named * _CompositeClassProto is not useful as dataclasses have no methods / bases we can use, so composite is against Any * Adjust session.get() feature to work w/ dataclass composites Change-Id: Icc606cc76871c738dc794ea4555fca8a1ab0e0fd
* Merge "establish sessionmaker and async_sessionmaker as generic" into mainmike bayer2022-05-311-0/+88
|\
| * establish sessionmaker and async_sessionmaker as genericMike Bayer2022-05-311-0/+88
| | | | | | | | | | | | | | | | | | | | | | This is so that custom Session and AsyncSession classes can be typed for these factories. Added appropriate typevars to `__call__()`, `__enter__()` and other methods so that a custom Session or AsyncSession subclass is carried through. Fixes: #7656 Change-Id: Ia2b8c1f22b4410db26005c3285f6ba3d13d7f0e0
* | add typing for PG UUID, other typesMike Bayer2022-05-271-2/+35
|/ | | | | | | note that UUID will be generalized into core with #7212. Fixes: #6402 Change-Id: I90f0052ca74367c2c2f1ce2f8a90e81d173d1430
* apply bindparam escape name to processors dictionaryMike Bayer2022-05-251-1/+1
| | | | | | | | | | | | | Fixed SQL compiler issue where the "bind processing" function for a bound parameter would not be correctly applied to a bound value if the bound parameter's name were "escaped". Concretely, this applies, among other cases, to Oracle when a :class:`.Column` has a name that itself requires quoting, such that the quoting-required name is then used for the bound parameters generated within DML statements, and the datatype in use requires bind processing, such as the :class:`.Enum` datatype. Fixes: #8053 Change-Id: I39d060a87e240b4ebcfccaa9c535e971b7255d99
* use plainto_tsquery for PG matchMike Bayer2022-05-221-0/+7
| | | | | | | | | | | | | | | | The :meth:`.Operators.match` operator now uses ``plainto_tsquery()`` for PostgreSQL full text search, rather than ``to_tsquery()``. The rationale for this change is to provide better cross-compatibility with match on other database backends. Full support for all PostgreSQL full text functions remains available through the use of :data:`.func` in conjunction with :meth:`.Operators.bool_op` (an improved version of :meth:`.Operators.op` for boolean operators). Additional doc updates here apply to 1.4 so will backport these out to a separate commit. Fixes: #7086 Change-Id: I1946075daf5d9c558e85f73f1bf852604b3b1b8c
* revenge of pep 484Mike Bayer2022-05-152-1/+68
| | | | | | trying to get remaining must-haves for ORM Change-Id: I66a3ecbbb8e5ba37c818c8a92737b576ecf012f7
* update for flake8-future-imports 0.0.5Mike Bayer2022-05-141-1/+1
| | | | | | | | a whole bunch of errors were apparently blocked by 0.0.4 being installed. Fixes: #8020 Change-Id: I22a0faeaabe03de501897893391946d677c2df7e
* accept for literal coercionsMike Bayer2022-05-061-0/+37
| | | | | | | this may be needed in many more places but cast() is a prominent one. Change-Id: I5331edd2d34c54910e4ca16b0553f64fc9167af7
* pep484 ORM / SQL result supportMike Bayer2022-04-2713-65/+1099
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | after some experimentation it seems mypy is more amenable to the generic types being fully integrated rather than having separate spin-off types. so key structures like Result, Row, Select become generic. For DML Insert, Update, Delete, these are spun into type-specific subclasses ReturningInsert, ReturningUpdate, ReturningDelete, which is fine since the "row-ness" of these constructs doesn't happen until returning() is called in any case. a Tuple based model is then integrated so that these objects can carry along information about their return types. Overloads at the .execute() level carry through the Tuple from the invoked object to the result. To suit the issue of AliasedClass generating attributes that are dynamic, experimented with a custom subclass AsAliased, but then just settled on having aliased() lie to the type checker and return `Type[_O]`, essentially. will need some type-related accessors for with_polymorphic() also. Additionally, identified an issue in Update when used "mysql style" against a join(), it basically doesn't work if asked to UPDATE two tables on the same column name. added an error message to the specific condition where it happens with a very non-specific error message that we hit a thing we can't do right now, suggest multi-table update as a possible cause. Change-Id: I5eff7eefe1d6166ee74160b2785c5e6a81fa8b95
* pep-484: ORM public API, constructorsMike Bayer2022-04-2010-51/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for the moment, abandoning using @overload with relationship() and mapped_column(). The overloads are very difficult to get working at all, and the overloads that were there all wouldn't pass on mypy. various techniques of getting them to "work", meaning having right hand side dictate what's legal on the left, have mixed success and wont give consistent results; additionally, it's legal to have Optional / non-optional independent of nullable in any case for columns. relationship cases are less ambiguous but mypy was not going along with things. we have a comprehensive system of allowing left side annotations to drive the right side, in the absense of explicit settings on the right. so type-centric SQLAlchemy will be left-side driven just like dataclasses, and the various flags and switches on the right side will just not be needed very much. in other matters, one surprise, forgot to remove string support from orm.join(A, B, "somename") or do deprecations for it in 1.4. This is a really not-directly-used structure barely mentioned in the docs for many years, the example shows a relationship being used, not a string, so we will just change it to raise the usual error here. Change-Id: Iefbbb8d34548b538023890ab8b7c9a5d9496ec6e
* pep484: schema APIMike Bayer2022-04-151-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | implement strict typing for schema.py this module has lots of public API, lots of old decisions and very hard to follow construction sequences in many cases, and is also where we get a lot of new feature requests, so strict typing should help keep things clean. among improvements here, fixed the pool .info getters and also figured out how to get ColumnCollection and related to be covariant so that we may set them up as returning Column or ColumnClause without any conflicts. DDL was affected, noting that superclasses of DDLElement (_DDLCompiles, added recently) can now be passed into "ddl_if" callables; reorganized ddl into ExecutableDDLElement as a new name for DDLElement and _DDLCompiles renamed to BaseDDLElement. setting up strict also located an API use case that is completely broken, which is connection.execute(some_default) returns a scalar value. This case has been deprecated and new paths have been set up so that connection.scalar() may be used. This likely wasn't possible in previous versions because scalar() would assume a CursorResult. The scalar() change also impacts Session as we have explicit support (since someone had reported it as a regression) for session.execute(Sequence()) to work. They will get the same deprecation message (which omits the word "Connection", just uses ".execute()" and ".scalar()") and they can then use Session.scalar() as well. Getting this to type correctly while still supporting ORM use cases required some refactoring, and I also set up a keyword only delimeter for Session.execute() and related as execution_options / bind_arguments should always be keyword only, applied these changes to AsyncSession as well. Additionally simpify Table __init__ now that we are Python 3 only, we can have positional plus explicit kwargs finally. Simplify Column.__init__ as well again taking advantage of kw only arguments. Fill in most/all __init__ methods in sqltypes.py as the constructor for types is most of the API. should likely do this for dialect-specific types as well. Apply _InfoType for all info attributes as should have been done originally and update descriptor decorators. Change-Id: I3f9f8ff3f1c8858471ff4545ac83d68c88107527
* pep-484: asyncioMike Bayer2022-04-112-2/+80
| | | | | | | | | | | | | | | | | | | | | in this patch the asyncio/events.py module, which existed only to raise errors when trying to attach event listeners, is removed, as we were already coding an asyncio-specific workaround in upstream Pool / Session to raise this error, just moved the error out to the target and did the same thing for Engine. We also add an async_sessionmaker class. The initial rationale here is because sessionmaker() is hardcoded to Session subclasses, and there's not a way to get the use case of sessionmaker(class_=AsyncSession) to type correctly without changing the sessionmaker() symbol itself to be a function and not a class, which gets too complicated for what this is. Additionally, _SessionClassMethods has only three methods on it, one of which is not usable with asyncio (close_all()), the others not generally used from the session class. Change-Id: I064a5fa5d91cc8d5bbe9597437536e37b4e801fe
* pep-484: session, instancestate, etcMike Bayer2022-04-121-0/+50
| | | | | | | | Also adds some fixes to annotation-based mapping that have come up, as well as starts to add more pep-484 test cases Change-Id: Ia722bbbc7967a11b23b66c8084eb61df9d233fee
* update flake8 noqa skips with proper syntaxFederico Caselli2022-04-116-7/+7
| | | | Change-Id: I42ed77f559e3ee5b8c600d98457ee37803ef0ea6
* bump black to 22.3.0Mike Bayer2022-03-281-1/+1
| | | | | | | | | both black and click were released in the past few hours, and black 21.5b1 seems to suddenly be failing on a missing symbol from click. just update to the latest Change-Id: Idf76732479a264f7f2245699a6bdaff018e3a123
* pep 484 for typesMike Bayer2022-03-191-1/+2
| | | | | | | strict types type_api.py, including TypeDecorator, NativeForEmulated, etc. Change-Id: Ib2eba26de0981324a83733954cb7044a29bbd7db
* pep484 for hybridMike Bayer2022-03-173-1/+155
| | | | | Change-Id: I53274b13094d996e11b04acb03f9613edbddf87f References: #6810
* pep-484 - SQL column operationsMike Bayer2022-03-152-0/+60
| | | | | | | | | note we are taking out the ColumnOperartors[SQLCoreOperations] thing; not really clear why that was needed and at the moment it seems I was likely confused. Change-Id: I834b75f9b44f91b97e29f2e1a7b1029bd910e0a1
* pep484 + abc bases for assocaitionproxyMike Bayer2022-03-012-0/+67
| | | | | | | | | | went to this one next as it was going to be hard, and also exercises the ORM expression hierarchy a bit. made some adjustments to SQLCoreOperations etc. Change-Id: Ie5dde9218dc1318252826b766d3e70b17dd24ea7 References: #6810 References: #7774
* establish mypy / typing approach for v2.0Mike Bayer2022-02-1355-72/+577
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | large patch to get ORM / typing efforts started. this is to support adding new test cases to mypy, support dropping sqlalchemy2-stubs entirely from the test suite, validate major ORM typing reorganization to eliminate the need for the mypy plugin. * New declarative approach which uses annotation introspection, fixes: #7535 * Mapped[] is now at the base of all ORM constructs that find themselves in classes, to support direct typing without plugins * Mypy plugin updated for new typing structures * Mypy test suite broken out into "plugin" tests vs. "plain" tests, and enhanced to better support test structures where we assert that various objects are introspected by the type checker as we expect. as we go forward with typing, we will add new use cases to "plain" where we can assert that types are introspected as we expect. * For typing support, users will be much more exposed to the class names of things. Add these all to "sqlalchemy" import space. * Column(ForeignKey()) no longer needs to be `@declared_attr` if the FK refers to a remote table * composite() attributes mapped to a dataclass no longer need to implement a `__composite_values__()` method * with_variant() accepts multiple dialect names Change-Id: I22797c0be73a8fbbd2d6f5e0c0b7258b17fe145d Fixes: #7535 Fixes: #7551 References: #6810
* replace test tags with pytest.markMike Bayer2022-01-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | replaced the __tags__ class attribute and the --exclude-tags / --include-tags test runner options with regular pytest.mark names so that we can take advantage of mark expressions. options --nomemory, --notimingintensive, --backend-only, --exclude-tags, --include-tags remain as legacy but make use of pytest mark for implemementation. Added a "mypy" mark for the section of tests that are doing mypy integration tests. The __backend__ and __sparse_backend__ class attributes also use pytest marks for their implementation, which also allows the marks "backend" and "sparse_backend" to be used explicitly. Also removed the no longer used "--cdecimal" option as this was python 2 specific. in theory, the usage of pytest marks could expand such that the whole exclusions system would be based on it, but this does not seem to have any advantage at the moment. Change-Id: Ideeb57d9d49f0efc7fc0b6b923b31207ab783025
* Clean up most py3k compatFederico Caselli2021-11-241-2/+4
| | | | Change-Id: I8172fdcc3103ff92aa049827728484c8779af6b7
* Remove object in class definitionFederico Caselli2021-11-223-3/+3
| | | | | References: #4600 Change-Id: I2a62ddfe00bc562720f0eae700a497495d7a987a
* use typing.DictMike Bayer2021-11-182-4/+6
| | | | | | | | | newer Pythons seem to accept ``dict[Any, Any]`` which is why this wasn't noticed. Revise fix for #7321 made in I55656e867876677c5c55143449db371344be8600. Fixes: #7321 Change-Id: Idc22e15d098543e07853f4532cfd1aaae4dd6404
* handle dunder names in @declared_attr separatelyMike Bayer2021-11-172-0/+48
| | | | | | | | | | | | | | | | Fixed Mypy crash which would occur when using Mypy plugin against code which made use of :class:`_orm.declared_attr` methods for non-mapped names like ``__mapper_args__``, ``__table_args__``, or other dunder names, as the plugin would try to interpret these as mapped attributes which would then be later mis-handled. As part of this change, the decorated function is still converted by the plugin into a generic assignment statement (e.g. ``__mapper_args__: Any``) so that the argument signature can continue to be annotated in the same way one would for any other ``@classmethod`` without Mypy complaining about the wrong argument type for a method that isn't explicitly ``@classmethod``. Fixes: #7321 Change-Id: I55656e867876677c5c55143449db371344be8600
* fix(6435): support `MemberExpr` for enum column declarationHiroshi Ogawa2021-10-053-0/+38
| | | | | | | | | | | | | Fixed issue in mypy plugin to improve upon some issues detecting ``Enum()`` SQL types containing custom Python enumeration classes. Pull request courtesy Hiroshi Ogawa. Fixes: #6435 Closes: #7048 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7048 Pull-request-sha: 59f5c89688792f6af3b07488d5cf97f8f2e964dc Change-Id: I05adbec74ceac1ecfdc5a242bfe7aa4b2eb805e4
* dont assume argument lists for column propertyMike Bayer2021-08-271-0/+32
| | | | | | | | Fixed issue where mypy plugin would crash when interpreting a ``query_expression()`` construct. Fixes: #6950 Change-Id: Ic1f28d135bf6eb05c92061430c0d5a3663b804ef
* ensure "sqlalchemy" info set for all considered classesMike Bayer2021-08-251-0/+27
| | | | | | | | | Fixed issue in mypy plugin where columns on a mixin would not be correctly interpreted if the mapped class relied upon a ``__tablename__`` routine that came from a superclass. Fixes: #6937 Change-Id: I74aed4862d0545008ee67f781aaa794ab6866926
* Merge "Refactor mypy plugin"mike bayer2021-08-071-0/+41
|\
| * Refactor mypy pluginBryan Forbes2021-08-071-0/+41
| | | | | | | | | | | | | | | | | | | | A major refactor of the mypy plugin Closes: #6764 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6764 Pull-request-sha: 3e2295b2da7b57a6669f26db0df78f6409934184 Change-Id: I067d56dcfbc998ddd1b22a448f756859428b9e31
* | Merge "Fix type"mike bayer2021-07-291-1/+2
|\ \
| * | Fix typeKazantcev Andrey2021-07-221-1/+2
| |/ | | | | | | | | | | | | | | | | | | https://github.com/sqlalchemy/sqlalchemy2-stubs/pull/132#issuecomment-883159494 Closes: #6789 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6789 Pull-request-sha: 36e9075a8ee0ff699deea8ceef6e72ed4bc1d854 Change-Id: I87fe210b5d69c1e2500fb8e1440592ff44ceaacf
* | Add mypy tests on github.Federico Caselli2021-07-222-1/+15
|/ | | | | | Support skipping mypy tests based on interpreter version Change-Id: I98963318dbb2e7e097ad5518e0e4022349ca9779
* adjust patchfile from 6ca7c2ebMike Bayer2021-06-211-4/+5
| | | | | | | code formatting modified table.py such that the patchfile would no longer apply and this was missed in review. Change-Id: I0af91cf92baa79f196b4d9f3af1bab3bb0984a23
* accommodate no cls info found in _scan_declarativeMike Bayer2021-06-214-0/+20
| | | | | | | | | Fixed issue in mypy plugin where class info for a custom declarative base would not be handled correctly on a cached mypy pass, leading to an AssertionError being raised. Fixes: #6476 Change-Id: If78340673e6a4d16d8f7cf787ce3bdb02c8bd47b
* Update black flak8 and zimportsFederico Caselli2021-05-121-2/+3
| | | | Change-Id: I488c9557eda390e4a88319affd4c8813ee274f80