Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

~bool deprecation not reported for literals #134280

Open
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@decorator-factory

Description

@decorator-factory

Bug report

Bug description:

Related to:#103487

# literal.pyprint(~False)print(~True)# var.pya=Trueprint(~a)b=Falseprint(~b)

A DeprecationWarning is reported forvar.py, but not forliteral.py.

$ python -c 'import sys; print(sys.version)'3.15.0a0 (heads/main:42d03f3, May 19 2025, 23:32:01) [GCC 15.1.1 20250425 (Red Hat 15.1.1-1)]$ python literal.py-1-2$ python var.py/tmp/scratch/var.py:2: DeprecationWarning: Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.  print(~a)-2/tmp/scratch/var.py:5: DeprecationWarning: Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.  print(~b)-1

What's interesting is that there's a test for this:

withself.assertWarns(DeprecationWarning):
# also check that the warning is issued in case of constant
# folding at compile time
self.assertEqual(eval("~False"),-1)
and the DeprecationWarningis raised ifeval("~True") is used instead of just~True

$ python -c 'print(~True)'-2$ python -c 'print(eval("~True"))'<string>:1: DeprecationWarning: Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.-2

CPython versions tested on:

CPython main branch, 3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp