Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] gh-90016: Reword sqlite3 adapter/converter docs #93095

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented May 23, 2022

No description provided.

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 23, 2022

Step one of gh-90016: reword adapter/converter section and add recipes. The latter point is very much a work in progress; I will incorporate some of Serhiy's suggestions here before marking this as ready for review.

We will backport this to 3.11 and 3.10, and then deprecate the default adapters/converters (in main only).

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 23, 2022

I also took the liberty of normalising the argument spec of register_adapter and register_converter; they are positional only, so the naming is irrelevant to the functionality of these methods. However, I would like to use this opportunity to normalise the docstrings.

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 23, 2022

For new reviewers: suggestions to how to help reviewing this PR:

  • rewording: improve my English; I'm not a native speaker
  • userfriendlyness: is the rewritten docs more userfriendly or less userfriendly? why? how can it be improved?
  • examples: do the examples make sense? are they easily understood? how can they be improved?
  • brevity/verboseness: is this part of the docs too verbose? or the opposite? are there redundant passages (I said the same thing twice using different wordings)?
  • are there obvious reST markup issues?

type as tp: unicode
callable as converter: object
Copy link
Member

@serhiy-storchaka serhiy-storchaka May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? The former names looked cleaner to me, and type can be confused with actual type, as in register_adapter().

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about typename? I'll also revert the second argument back to converter.

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adressed in 82cf3e2. I changed type to typename. IMO, that's an improvement.

@@ -108,16 +108,16 @@ pysqlite_complete_statement_impl(PyObject *module, const char *statement)
_sqlite3.register_adapter as pysqlite_register_adapter
type: object(type='PyTypeObject *')
caster: object
callable as adapter: object
Copy link
Member

@serhiy-storchaka serhiy-storchaka May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change both the Python and the C names?

The syntax "as" in Argument Clinic was introduced for the case if the Python name and the C name are different and you do not want to rewrite existing C code (or cannot if it is a reserved word). If you change the C name in any case, there is no need in "as".

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was that the Python argument spec used normalised names (type, callable) for both adapters and converters, but the C code used more direct names, as I found it slightly more readable. However, it does add little value, now that I look at it again. (It also helps with new eyes on the code.)

I still want to normalise the Python argument spec in some kind of way, but it is not very important for me, I can leave it out. Currently register_adapter uses (type, caster), and register_converter uses (name, converter).

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adressed in 82cf3e2.

*detect_types* defaults to 0 (type detection disabled).
Set it to any combination of :const:`PARSE_DECLTYPES` and
:const:`PARSE_COLNAMES` to enable type detection.
Types cannot be detected for generated fields (for example ``max(data)``),
Copy link
Member

@serhiy-storchaka serhiy-storchaka May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it only related to PARSE_DECLTYPES or to PARSE_COLNAMES too? Does SELECT max(data) as "max(data) [integer]" work?

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect it to work, but I haven't tried. EDIT: It works.

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I'm not sure that sentence adds real value for the user. IMO, the documentation of the flags says what's needed to know about this.

Doc/library/sqlite3.rst Outdated Show resolved Hide resolved
SQLite's supported types. The callable *callable* accepts as single parameter
the Python value, and must return a value of the following types: int,
float, str or bytes.
Register *callable* to adapt Python *type* into an SQLite type.
Copy link
Member

@serhiy-storchaka serhiy-storchaka May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My English is poor, but the former wording looks more grammatically correct to me. Emphasized *callable* and *type* are names of parameters. Either callable *callable* or a callable.

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll come up with something. Thanks!

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded in 82cf3e2

/
Registers an adapter with sqlite3's adapter registry.
Register a function to adapt Python types to SQLite types.
Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is better:

Suggested change
Register a function to adapt Python types to SQLite types.
Register a function to adapt Python objects to SQLite values.

/
Registers a converter with sqlite3.
Register a function to convert SQLite types to Python types.
Copy link
Contributor Author

@erlend-aasland erlend-aasland May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is better:

Suggested change
Register a function to convert SQLite types to Python types.
Register a function to convert SQLite values to Python objects.

- revert most argument spec changes
- align argument spec across docstrings/docs
- improve wording of register_adapter/register_converter
- undo note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants