Commit Graph

79 Commits

Author SHA1 Message Date
Harry Lees 961f076230 Unify doc typing
### Description
<!-- Describe your changes in detail -->

Fixes #9168

This PR replaces common occurrences of [PEP 585](https://peps.python.org/pep-0585/) style type annotations with annotations compatible with older versions of Python.

I searched for instances of the following supported types from the PEP and replaced with their legacy typing couterparts.

* tuple # typing.Tuple
* list # typing.List
* dict # typing.Dict
* set # typing.Set
* frozenset # typing.FrozenSet
* type # typing.Type

```
grep -r "list\[.*\]" ./build --exclude-dir="./build/venv/*" --exclude-dir="./build/output/*" --exclude="changelog_[0-9]*\.rst"
```

I excluded changelog files from being altered, I think some of these could be changed if necessary but others are likely to require manual checking as the change may target the new typing style specifically.

For any examples that included imports, I tried to ensure that the correct typing imports were included and properly ordered.

### 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:

- [x] A documentation / typographical 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.

Closes: #9198
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9198
Pull-request-sha: 05ad4651b5

Change-Id: I41b93b3dee85f9fe00cfbb3d3eb011212795de29
2023-01-31 19:45:48 +00:00
Mike Bayer e82a5f19e1 reword INSERT explanation
Change-Id: I08460f0a77131c8c1406c3496e9d64a5a26bf6ff
2023-01-19 09:43:19 -05:00
Federico Caselli 8b4b26e709 avoid confusion in rst comment
Change-Id: I6e971f7445ae19f73097516b58776ab05a5371f1
2023-01-18 23:02:48 +01:00
Mike Bayer 6da2f72b11 super-fine pass through the metadata tutorial
try to keep the wordiness down here, using sidebars
and topics for non-essential information.   Sphinx seems
to read out attrs from under TYPE_CHECKING sections now
so link out the attrs in DeclarativeBase w/ docstrings,
not sure why we didn't think of this earlier.  looks great

Change-Id: Ib2e07e3606185998561c2d77b2564fd3eddb4d75
2023-01-15 13:11:38 -05:00
Mike Bayer 48eed9eb9c fix orm-header for standalone
Change-Id: I20e7f8ad5800c2ce5cdc9645c4dbe66f53b8cdf8
2023-01-15 11:28:49 -05:00
Mike Bayer 0c5faf37c2 fix typo
Change-Id: I273459175a3c55290b1f6c28f656ed9c4db17ccf
2023-01-13 14:31:28 -05:00
Federico Caselli b04b7527ed Make the custom type map more discoverable
Change-Id: Id6cdaddad83aa93508e256e54010a6c53218b717
2023-01-13 10:40:19 -05:00
Federico Caselli 06d584ad4b Fixes related to improved sql formatting
Follow up of I07b72e6620bb64e329d6b641afa27631e91c4f16

Change-Id: I1f61974bf9cdc3da5317e546d4f9b649c2029e4d
2023-01-12 23:03:03 +01:00
Federico Caselli dce11383f8 Improve sql formatting
change {opensql} to {printsql} in prints, add missing markers

Change-Id: I07b72e6620bb64e329d6b641afa27631e91c4f16
2023-01-11 20:24:29 +01:00
Mike Bayer 2f09374d44 remove anchor removed by mistake
Change-Id: I20e196f63c8cea9cd805501ab174cab320575b05
2023-01-09 15:20:39 -05:00
Mike Bayer c30a48604c fix inconsistent title level
Change-Id: I954818fdf9f5b56a895dbfdaf191c4c5867b574f
2023-01-09 15:16:50 -05:00
Mike Bayer 1e7d452836 more thoughts on tutorial presentation of ORM /Core
Change-Id: Iaa0c160e3f8285f1ca989dcb12b86de15ea82f03
2023-01-04 15:17:26 -05:00
Mike Bayer 72268e9387 tutorial updates re: Core /ORM commonality
updates for Insert / bulk insert, executemanyvalues,
as well as beginning to describe Table / declared class more
closely together, mentioning typing support.

Fixed a long-standing issue where sphinx would complain about
the Insert symbol being ambiguous.

Change-Id: Id4cc09b9581e8fa39c9c00bc8f229636e626e9bc
2023-01-03 18:21:25 -05:00
Mike Bayer 3d8d366e1b Oracle COLUMN_VALUE is a column name, not a keyword
Fixed issue in Oracle compiler where the syntax for
:meth:`.FunctionElement.column_valued` was incorrect, rendering the name
``COLUMN_VALUE`` without qualifying the source table correctly.

Fixes: #8945
Change-Id: Ia04bbdc68168e78b67a74bb3834a63f5d5000627
2022-12-07 17:28:49 -05:00
Andy Garfield 36954a3dbb Small tutorial rewording
The language is this sentence took me a few reads to understand. This is just a rewording.
2022-11-15 11:28:58 -05:00
Mike Bayer 80372f6c4c further 2.0 modernizations
biggest change here is the old tutorials were removed from the
TOC and some additional links to them have been corrected.

Change-Id: I79b878a946422eac24ed2449b440fc5d556576c4
2022-10-13 10:13:01 -04:00
Mike Bayer cfd5b3e78f fixes for doc builds
* requirements needs typing_extensions
* update all "future=True" references to be appropriate to 2.0

Change-Id: I2eeb0ae65afdb587f21aeb0020f1d8a292f67c21
2022-10-13 09:12:04 -04:00
Mike Bayer d4b8b41832 update executemany for new features
also fixes issue in format_docs_code which didn't work with
pre-commit for more than one file.  will backport

Fixes: #8597
Change-Id: I21b2625514987b1cd90f7c00f06e72e57e257390
2022-10-11 15:29:15 -04:00
Mike Bayer 6c180ab743 the future is here
the autodoc for the "future" Engine / Connection were removed,
so all these links weren't working.   Replace all _future
for these with _engine.  There was just one _future pointing
to select, changed that separately.

Change-Id: Ib28270d8da8616b533953204e22eabee9388d620
2022-10-02 21:26:22 -04:00
Federico Caselli 04a72ff3a9 Add proper code block formatting
Change-Id: I63585eeae0b0bc78109da64520696928dfb3982c
2022-10-02 11:51:02 -04:00
Federico Caselli dcbda9f1ea Improvements to code formatter
Change-Id: I75cf7143f3ed3bbc09aa8bc18edbce5c8af0f0be
2022-10-02 10:55:42 -04:00
Mike Bayer b2c20d8a53 add disable doctest tag for autodoc test suite
ahead of trying to get everything formatted, some more
flexibility so that we can use doctest for all
python + sql code, while still being able to tell the
test suite to not run doctests on a sample.    All of the
"non-console python with SQL" in the docs is because I was
showing an example that I didn't want tested.

Change-Id: Iae876ae1ffd93c36b096c6c2d6048843ae9698c8
2022-10-01 22:36:03 -04:00
Federico Caselli 23dbf572ce Format code in the rst docs file
Added script to format code in the rst documentation using black.
This is also added to the lint tox job to ensure that the code
in the docs is properly formatted.

Change-Id: I799444f22da153484ca5f095d57755762348da40
2022-09-30 14:39:48 -04:00
Mike Bayer 81d8394c0b New ORM Query Guide featuring DML support
reviewers:  these docs publish periodically at:
https://docs.sqlalchemy.org/en/gerrit/4042/orm/queryguide/index.html

See the "last generated" timestamp near the bottom of the
page to ensure the latest version is up

Change includes some other adjustments:

* small typing fixes for end-user benefit
* removal of a bunch of old examples for patterns that nobody
  uses or aren't really what we promote now
* modernization of some examples, including inheritance

Change-Id: I9929daab7797be9515f71c888b28af1209e789ff
2022-09-25 19:38:10 -04:00
Mike Bayer 2bcc97da42 implement batched INSERT..VALUES () () for executemany
the feature is enabled for all built in backends
when RETURNING is used,
except for Oracle that doesn't need it,  and on
psycopg2 and mssql+pyodbc it is used for all INSERT statements,
not just those that use RETURNING.

third party dialects would need to opt in to the new feature
by setting use_insertmanyvalues to True.

Also adds dialect-level guards against using returning
with executemany where we dont have an implementation to
suit it.   execute single w/ returning still defers to the
server without us checking.

Fixes: #6047
Fixes: #7907
Change-Id: I3936d3c00003f02e322f2e43fb949d0e6e568304
2022-09-24 11:15:32 -04:00
Mike Bayer f0bcd57f9e remove obtuse section about "bundled bind parameters"
Just looking for basics on insert in the first pages
of the tutorial I see this weird detour into something that
nobody ever uses and definitely isn't going to make sense
to the people I see complaining about our docs on twitter,
remove this.   the tutorial probably needs a big sweep
for wordy obtuse things.  the userbase is changing and
we really have a lot of brand-new-to-programming types coming
in.

Change-Id: I3bb11f0399e55edbb8f874e7eb63c40616b04e8b
2022-09-17 10:18:56 -04:00
Mike Bayer cc72081b0c add docs for session.get()
also use the term "primary key" a bit more

Change-Id: Ib654b30a9d06a2aeed019b4754db920afe05d774
References: https://twitter.com/encthenet/status/1567644850471989248
2022-09-07 19:00:31 -04:00
Mike Bayer 1ecbf14cc2 implement tuple-slices from .c collections
Added new syntax to the ``.c`` collection on all :class:`.FromClause`
objects allowing tuples of keys to be passed to ``__getitem__()``, along
with support for ``select()`` handling of ``.c`` collections directly,
allowing the syntax ``select(table.c['a', 'b', 'c'])`` to be possible. The
sub-collection returned is itself a :class:`.ColumnCollection` which is
also directly consumable by :func:`_sql.select` and similar now.

Fixes: #8285
Change-Id: I2236662c477ffc50af079310589e213323c960d1
2022-08-01 21:46:33 +00:00
Mike Bayer 9a37ebdf99 update ORM declarative docs for new features
I screwed up a rebase or something so this was
temporarily in Ic51a12de3358f3a451bd7cf3542b375569499fc1

Change-Id: I847ee1336381221c0112b67854df022edf596b25
2022-07-16 16:28:11 -04:00
Jefferson Oliveira 52317cec36 fix documentation typo 2022-06-29 11:53:36 -03:00
Mike Bayer c7519e94b5 sub-categorize special function forms
this is the tutorial, which should have some semblence of
not getting too far into the weeds.  however, as we dont
really have other places to explain SQL concepts, and SQL
functions have a lot of them, we dont have another home right
now.  so at least further sub-categorize window functions,
table/column valued functions, and WITHIN GROUP into an
"advanced function techniques" section with a disclaimer that
these are less common use cases.

Change-Id: I4b16bd5673c0bd39a9b880338f6ce3cfbafbe271
2022-06-22 18:50:35 -04:00
Federico Caselli db08a69948 rearchitect reflection for batched performance
Rearchitected the schema reflection API to allow some dialects to make use
of high performing batch queries to reflect the schemas of many tables at
once using much fewer queries. The new performance features are targeted
first at the PostgreSQL and Oracle backends, and may be applied to any
dialect that makes use of SELECT queries against system catalog tables to
reflect tables (currently this omits the MySQL and SQLite dialects which
instead make use of parsing the "CREATE TABLE" statement, however these
dialects do not have a pre-existing performance issue with reflection. MS
SQL Server is still a TODO).

The new API is backwards compatible with the previous system, and should
require no changes to third party dialects to retain compatibility;
third party dialects can also opt into the new system by implementing
batched queries for schema reflection.

Along with this change is an updated reflection API that is fully
:pep:`484` typed, features many new methods and some changes.

Fixes: #4379
Change-Id: I897ec09843543aa7012bcdce758792ed3d415d08
2022-06-18 14:57:26 -04:00
Mike Bayer 1c99edf1b9 migrate labels to new tutorial
other org changes and some sections from old tutorial
ported to new tutorial.

Change-Id: Ic0fba60ec82fff481890887beef9ed0fa271875a
2022-06-07 12:25:19 -04:00
Robert Kulagowski b66d57451a Update dbapi_transactions.rst (#8032)
If you're defining 'y=row.y' then you might as well use 'y' in the print statement.
2022-05-18 22:25:18 +02:00
Mike Bayer 5e88e6e89a fix most sphinx warnings (1.4)
still can't figure out the warnings with some of the older
changelog files.

this cherry-picks the sphinx fixes from 1.4 and additionally
fixes a small number of new issues in the 2.0 docs. However,
2.0 has many more errors to fix, primarily from the removal
of the legacy tutorials left behind a lot of labels that need
to be re-linked to the new tutorial.

Fixes: #7946
Change-Id: Id657ab23008eed0b133fed65b2f9ea75a626215c
(cherry picked from commit 9b55a42345)
2022-05-16 11:21:36 -04:00
Mike Bayer cd628fad7c more expire_on_commit reminders
the session commit/close docs still feel awkward in how
one learns about this operation.   hopefully another pass
over 2.0 can make things more linear.

removed a 1.4 note about autobegin that was completely inaccurate;
commit() does autobegin so it has an effect, just not usually
on the database.

Change-Id: Iaa4b96bd3df6cf82e851b2943322ddad7abbbac0
2022-05-13 10:25:37 -04:00
Mike Bayer 1dffb7cede clarify alternative mapping example
this second example is not part of the doctest steps,
clarify that it's not part of code examples to be present
in execution steps.   Add an extra registry +
declarative base on top
so that even if someone does run it, the Base will have
been reset and the examples will continue to work
(noting that column order in statements may change, but
probably nothing else).

Fixes: #7891
Change-Id: Icb1ba310230841e502185d9d0cadd3c18d467292
2022-04-03 10:52:30 -04:00
Maple 2ea12b2f5c fix small indentation typo (#7882) 2022-04-03 11:30:08 +02:00
Mike Bayer 86fbd4a215 ORM quickstart
This is done in 1.4 style so it can be backported to 1.4.
Will put this up as is, we can work on it.   For 2.0, the
ORM mapping will be updated to mapped_column() style when
we do the full pass.

Change-Id: Icfdf81449973844dac244b3a107ce955a7d3b16c
2022-03-11 11:28:26 -05:00
Mike Bayer a4bb502cf9 pep-484 for engine
All modules in sqlalchemy.engine are strictly
typed with the exception of cursor, default, and
reflection.  cursor and default pass with non-strict
typing, reflection is waiting on the multi-reflection
refactor.

Behavioral changes:

* create_connect_args() methods return a tuple of list,
  dict, rather than a list of list, dict
* removed allow_chars parameter from
  pyodbc connector ._get_server_version_info()
  method
* the parameter list passed to do_executemany is now
  a list in all cases. previously, this was being run
  through dialect.execute_sequence_format, which
  defaults to tuple and was only intended for individual
  tuple params.
* broke up dialect.dbapi into dialect.import_dbapi
  class method and dialect.dbapi module object.  added
  a deprecation path for legacy dialects.  it's not
  really feasible to type a single attr as a classmethod
  vs. module type.  The "type_compiler" attribute also
  has this problem with greater ability to work around,
  left that one for now.
* lots of constants changing to be Enum, so that we can
  type them.  for fixed tuple-position constants in
  cursor.py / compiler.py (which are used to avoid the
  speed overhead of namedtuple), using Literal[value]
  which seems to work well
* some tightening up in Row regarding __getitem__, which
  we can do since we are on full 2.0 style result use
* altered the set_connection_execution_options and
  set_engine_execution_options event flows so that the
  dictionary of options may be mutated within the event
  hook, where it will then take effect as the actual
  options used.  Previously, changing the dict would
  be silently ignored which seems counter-intuitive
  and not very useful.
* A lot of DefaultDialect/DefaultExecutionContext
  methods and attributes, including underscored ones, move
  to interfaces.  This is not fully ideal as it means
  the Dialect/ExecutionContext interfaces aren't publicly
  subclassable directly, but their current purpose
  is more of documentation for dialect authors who should
  (and certainly are) still be subclassing the DefaultXYZ
  versions in all cases

Overall, Result was the most extremely difficult class
hierarchy to type here as this hierarchy passes through
largely amorphous "row" datatypes throughout, which
can in fact by all kinds of different things, like
raw DBAPI rows, or Row objects, or "scalar"/Any, but
at the same time these types have meaning so I tried still
maintaining some level of semantic markings for these,
it highlights how complex Result is now, as it's trying
to be extremely efficient and inlined while also being
very open-ended and extensible.

Change-Id: I98b75c0c09eab5355fc7a33ba41dd9874274f12a
2022-03-01 09:09:02 -05:00
luz paz 56256b6d13 Fix various source comment/doc typos
### Description
Found via `codespell -q 3 -L ba,crate,datas,froms,gord,hist,inh,nd,selectin,strat,ue`
Also added codespell to the pep8 tox env

### Checklist

This pull request is:

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

Closes: #7338
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7338
Pull-request-sha: 0deac22193

Change-Id: Icd61db31c8dc655d4a39d8a304194804d08555fe
2021-12-29 21:35:34 +01:00
Mike Bayer f05d3ddba4 initial 2.0 setup
Adapted from 55e64f857daeb6057b85ff67297a774b when we
previously started a 2.0 branch.

Change-Id: Ib5af75df94b23104eebe0e918adcf979d798ea3b
2021-10-30 14:21:53 -04:00
Mike Bayer 7cf3e79991 add sections for ORM use with UNION
this is a fairly non-obvious part of the new ORM
querying style and needs its own sections

Change-Id: Iacb176020d580066c1e0b7f2b40bfbbcb3587d76
2021-10-25 22:22:27 -04:00
JMcB17 222ea42ec5 Remove misplaced apostrophe in tutorial/index.rst (#7043)
Citation: http://www.sussex.ac.uk/informatics/punctuation/apostrophe/possessives
2021-09-19 18:30:24 +02:00
Kevin Kirsche a4abb4e396 fix: typos in doc/build/tutorial (#7005) 2021-09-08 21:14:56 +02:00
jonathan vanasco 369edbbd67 standardizing docs #6821
(redo of 2999/I5609025feee8cfdecc09b55bfbf1bd13fa2e6602)

This PR is designed to bring more clarity within the docs by renaming object
instances that may be consfusingly similar to class, method, and attribute names.

For example, instances of the class `MetaData` are available on some  objects as
`.metadata` property, and had appeared within the docs as both `meta` and
`metadata` which has confused some users in the past. By this PR, the docs now
utilize the following naming convention:

* MetaData - SQLAlchemy class
* .metadata - SQLAlchemy API attributes
* metadata_obj - developer instantiated metadata objects or references

Detailed Changes:

* standardized `meta` and `metadata` instances to `metadata_obj`. note: the docs were evenly split between 'meta' and 'metadata'.
* standardized 'cursor' to 'cursor_obj' to avoid confusion with the method.
* standardized a 'scalar_subquery = ' to 'scalar_subq' to avoid confusion with the method.
* standardized a 'cte = ' to 'cte_obj' to avoid confusion with the method

Change-Id: I79c98aee16c5fc6649289b2dd7d6dfc368222fb4
2021-08-23 16:25:21 -04:00
Federico Caselli fb81f9c8d9 Replace all http:// links to https://
Also replace http://pypi.python.org/pypi with https://pypi.org/project

Change-Id: I84b5005c39969a82140706472989f2a30b0c7685
2021-07-04 20:54:33 +02:00
Samuel Cattini-Schultz f0ad41eb6f Fix typos in "Working with Related Objects" docs (#6651)
* Fix typo in "Working with Related Objects" docs

* Fix typo in "Working with Related Objects" docs
2021-06-17 20:51:38 +02:00
Sebastián Ramírez 5b12393e81 ✏️ Fix minor typos in "Selecting Rows with Core or ORM" (#6381) 2021-04-28 20:42:12 +02:00
Sebastián Ramírez d69407abdb ✏️ Fix typos in "Data Manipulation with the ORM" (#6389) 2021-04-28 20:42:07 +02:00