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

GH-106008: Make implicit boolean conversions explicit#106003

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
brandtbucher merged 18 commits intopython:mainfrombrandtbucher:to-bool
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from16 commits
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
69781b4
Make boolean conversions in branches explicit
brandtbucherJun 6, 2023
5289c7f
Specialize UNARY_NOT
brandtbucherJun 6, 2023
7e5c9df
Remove unused stats
brandtbucherJun 7, 2023
27bb264
Make UNARY_NOT_BOOL a little bit slicker
brandtbucherJun 7, 2023
0463633
Replace UNARY_NOT with TO_BOOL
brandtbucherJun 9, 2023
d2932a1
Catch up with main
brandtbucherJun 21, 2023
47ec38f
Branchless branching
brandtbucherJun 21, 2023
a0bd53a
Add a "boolean conversion" bit to COMPARE_OP
brandtbucherJun 21, 2023
bab539b
More stats for heap types
brandtbucherJun 21, 2023
757b1cc
Specialize TO_BOOL_ALWAYS_TRUE
brandtbucherJun 21, 2023
f9fa498
Fix refleak and error handling
brandtbucherJun 21, 2023
0c14344
Catch up with main
brandtbucherJun 22, 2023
d314078
Cleanup
brandtbucherJun 23, 2023
9aa83b5
blurb add
brandtbucherJun 23, 2023
a76f11d
Docs
brandtbucherJun 23, 2023
c2d4a33
Clean up some commnts
brandtbucherJun 23, 2023
7638b76
Add cast
brandtbucherJun 29, 2023
6b4a598
Catch up with main
brandtbucherJun 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions.gitattributes
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,6 +86,7 @@ Parser/token.c generated
Programs/test_frozenmain.h generated
Python/Python-ast.c generated
Python/generated_cases.c.h generated
Python/opcode_metadata.h generated
Python/opcode_targets.h generated
Python/stdlib_module_names.h generated
Tools/peg_generator/pegen/grammar_parser.py generated
Expand Down
23 changes: 22 additions & 1 deletionDoc/library/dis.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -529,6 +529,9 @@ result back on the stack.

Implements ``STACK[-1] = not STACK[-1]``.

.. versionchanged:: 3.13
This instruction now requires an exact :class:`bool` operand.


.. opcode:: UNARY_INVERT

Expand All@@ -548,6 +551,13 @@ result back on the stack.
.. versionadded:: 3.5


.. opcode:: TO_BOOL

Implements ``STACK[-1] = bool(STACK[-1])``.

.. versionadded:: 3.13


**Binary and in-place operations**

Binary operations remove the top two items from the stack (``STACK[-1]`` and
Expand DownExpand Up@@ -1127,7 +1137,12 @@ iterations of the loop.
.. opcode:: COMPARE_OP (opname)

Performs a Boolean operation. The operation name can be found in
``cmp_op[opname]``.
``cmp_op[opname >> 5]``. If the fifth-lowest bit of ``opname`` is set
(``opname & 16``), the result should be coerced to ``bool``.

.. versionchanged:: 3.13
The fifth-lowest bit of the oparg now indicates a forced conversion to
:class:`bool`.


.. opcode:: IS_OP (invert)
Expand DownExpand Up@@ -1191,6 +1206,9 @@ iterations of the loop.
.. versionchanged:: 3.12
This is no longer a pseudo-instruction.

.. versionchanged:: 3.13
This instruction now requires an exact :class:`bool` operand.

.. opcode:: POP_JUMP_IF_FALSE (delta)

If ``STACK[-1]`` is false, increments the bytecode counter by *delta*.
Expand All@@ -1204,6 +1222,9 @@ iterations of the loop.
.. versionchanged:: 3.12
This is no longer a pseudo-instruction.

.. versionchanged:: 3.13
This instruction now requires an exact :class:`bool` operand.

.. opcode:: POP_JUMP_IF_NOT_NONE (delta)

If ``STACK[-1]`` is not ``None``, increments the bytecode counter by *delta*.
Expand Down
8 changes: 8 additions & 0 deletionsInclude/internal/pycore_code.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -101,6 +101,13 @@ typedef struct {

#define INLINE_CACHE_ENTRIES_SEND CACHE_ENTRIES(_PySendCache)

typedef struct {
uint16_t counter;
uint16_t version[2];
} _PyToBoolCache;

#define INLINE_CACHE_ENTRIES_TO_BOOL CACHE_ENTRIES(_PyToBoolCache)

// Borrowed references to common callables:
struct callable_cache {
PyObject *isinstance;
Expand DownExpand Up@@ -246,6 +253,7 @@ extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
int oparg);
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_Send(PyObject *receiver, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ToBool(PyObject *value, _Py_CODEUNIT *instr);

/* Finalizer function for static codeobjects used in deepfreeze.py */
extern void _PyStaticCode_Fini(PyCodeObject *co);
Expand Down
137 changes: 69 additions & 68 deletionsInclude/internal/pycore_opcode.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp