Skip to content

[ty] Report deprecated unary operations - #27584

Open
Andrej730 wants to merge 3 commits into
astral-sh:mainfrom
Andrej730:deprecated-bool-invert
Open

[ty] Report deprecated unary operations#27584
Andrej730 wants to merge 3 commits into
astral-sh:mainfrom
Andrej730:deprecated-bool-invert

Conversation

@Andrej730

Copy link
Copy Markdown
Contributor

Summary

Hi! Stumbled upon ~True not being reported as deprecated, went investigating and turned out there were two cases:

  • no deprecation check for any unary operation, now there is
  • no deprecation check for __invert__ and bool literals - now it tries to find __invert__ on bool and reports it as deprecated, otherwise it's using fallback which is covering the future, when bool.__invert__ will be completely removed

Examples:

# Reported before this PR as `deprecated`
True.__invert__ # deprecated


# Reported after this PR:
def test(a: bool):
    ~a  # deprecated

~True  # deprecated


from typing_extensions import deprecated

class A:
    @deprecated("deprecated!")
    def __invert__(self):
        ...

~A()  # deprecated
Example diagnostics
warning[deprecated]: The function `__invert__` is deprecated
 --> example_bool:2:6
  |
2 | True.__invert__ # deprecated
  |      ^^^^^^^^^^ Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

warning[deprecated]: The function `__invert__` is deprecated
 --> example_bool:7:5
  |
7 |     ~a  # deprecated
  |     ^^ Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

warning[deprecated]: The function `__invert__` is deprecated
 --> example_bool:9:1
  |
9 | ~True  # deprecated
  | ^^^^^ Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

warning[deprecated]: The function `__invert__` is deprecated
  --> example_bool:19:1
   |
19 | ~A()  # deprecated
   | ^^^^ deprecated!

Found 4 diagnostics

Test Plan

Added mdtest to deprecated.md, updated integers.md test to consider deprecation diagnostic. All previous tests also pass.

@Andrej730
Andrej730 requested a review from a team as a code owner August 7, 2026 20:26
@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Aug 7, 2026
@astral-sh-bot astral-sh-bot Bot changed the title [ty] Report deprecated unary operations [ty] [ty] Report deprecated unary operations Aug 7, 2026
@astral-sh-bot
astral-sh-bot Bot requested a review from carljm August 7, 2026 20:26
@Andrej730 Andrej730 changed the title [ty] [ty] Report deprecated unary operations [ty] Report deprecated unary operations Aug 7, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 96.96%. The percentage of expected errors that received a diagnostic held steady at 92.96%. The number of fully passing files held steady at 106/133.

@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
deprecated 16 0 0
Total 16 0 0

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Raw diff (16 changes)
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/categorical.py:3127:29 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ pandas/core/indexes/base.py:3901:32 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ pandas/tests/computation/test_eval.py:589:70 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ pandas/tests/computation/test_eval.py:593:71 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ pandas/tests/frame/test_reductions.py:2109:26 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ pandas/tests/frame/test_reductions.py:2109:39 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

pandera (https://github.com/pandera-dev/pandera)
+ pandera/backends/pyspark/builtin_checks.py:133:34 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ pandera/backends/pyspark/builtin_checks.py:157:34 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

scipy (https://github.com/scipy/scipy)
+ scipy/linalg/_decomp.py:45:28 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ scipy/ndimage/_measurements.py:689:12 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ scipy/ndimage/_measurements.py:691:10 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ scipy/ndimage/_measurements.py:697:16 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ scipy/stats/_stats_py.py:9240:45 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.
+ scipy/stats/_stats_py.py:9260:45 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

spark (https://github.com/apache/spark)
+ python/pyspark/ml/tests/test_feature.py:939:30 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_variable.py:458:22 warning[deprecated] The function `__invert__` is deprecated: Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.

Full report with detailed diff (timing results)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant