dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
570 stars 101 forks source link

1.4 deprecated operators are not supported correctly #237

Open rogalski opened 2 years ago

rogalski commented 2 years ago

SQLAlchemy 1.4 release notes: https://docs.sqlalchemy.org/en/14/changelog/changelog_14.html#change-8dd50c1cc4d512bf97b23fb0243619af

Several operators are renamed to achieve more consistent naming across SQLAlchemy.

The operator changes are:
    isfalse is now is_false
    isnot_distinct_from is now is_not_distinct_from
    istrue is now is_true
    notbetween is now not_between
    notcontains is now not_contains
    notendswith is now not_endswith
    notilike is now not_ilike
    notlike is now not_like
    notmatch is now not_match
    notstartswith is now not_startswith
    nullsfirst is now nulls_first
    nullslast is now nulls_last
    isnot is now is_not
    not_in_ is now not_in

Stubs needs to be updated:

Module "sqlalchemy.sql.expression" has no attribute "nulls_last"; maybe "nullslast"?

Version:

Successfully installed sqlalchemy-stubs-0.4
gward commented 2 months ago

It's a trifle more complex than the docs say. Operators exist as functions in sqlalchemy.sql.operators and as methods of sqlalchemy.sql.operators.ColumnOperators, and the names aren't quite consistent. Some of the module-level functions end with _op, and some don't.

Here's what I found out experimentally. First, module-level functions:

old name new name
isfalse is_false
isnot_distinct_from is_not_distinct_from
istrue is_true
notbetween_op not_between_op
notcontains_op not_contains_op
notendswith_op not_endswith_op
notilike_op not_ilike_op
notlike_op not_like_op
notmatch_op not_match_op
notstartswith_op not_startswith_op
nullsfirst_op nulls_first_op
nullslast_op nulls_last_op
isnot is_not
notin_op not_in_op

And methods of class ColumnOperators:

old name new name
isnot_distinct_from is_not_distinct_from
notilike not_ilike
notlike not_like
nullsfirst nulls_first
nullslast nulls_last
isnot is_not
notin_ not_in

PR coming shortly...