-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trivial inference tests for Python 3.12 support (#31170)
* Fix trivial inference for Python 3.12 support * remove debugging prints * Address comments * add unit test for intrinsic op order * linting * add unittest.main() * suggestions
- Loading branch information
1 parent
6197657
commit 287ed38
Showing
5 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""Defines the actions intrinsic bytecodes have on the frame. | ||
Each function here corresponds to a bytecode documented in | ||
https://docs.python.org/3/library/dis.html . The first argument is a (mutable) | ||
FrameState object, the second the integer opcode argument. | ||
Bytecodes with more complicated behavior (e.g. modifying the program counter) | ||
are handled inline rather than here. | ||
For internal use only; no backwards-compatibility guarantees. | ||
""" | ||
# pytype: skip-file | ||
|
||
from . import opcodes | ||
|
||
|
||
def intrinsic_1_invalid(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_print(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_import_star(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_stopiteration_error(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_async_gen_wrap(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_unary_positive(state, arg): | ||
opcodes.unary_positive(state, arg) | ||
pass | ||
|
||
|
||
def intrinsic_list_to_tuple(state, arg): | ||
opcodes.list_to_tuple(state, arg) | ||
pass | ||
|
||
|
||
def intrinsic_typevar(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_paramspec(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_typevartuple(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_subscript_generic(state, arg): | ||
pass | ||
|
||
|
||
def intrinsic_typealias(state, arg): | ||
pass | ||
|
||
|
||
# The order of operations in the table of the intrinsic one operations is | ||
# defined in https://docs.python.org/3/library/dis.html#opcode-CALL_INTRINSIC_1 | ||
# and may change between minor versions. | ||
INT_ONE_OPS = tuple([ | ||
intrinsic_1_invalid, | ||
intrinsic_print, | ||
intrinsic_import_star, | ||
intrinsic_stopiteration_error, | ||
intrinsic_async_gen_wrap, | ||
intrinsic_unary_positive, | ||
intrinsic_list_to_tuple, | ||
intrinsic_typevar, | ||
intrinsic_paramspec, | ||
intrinsic_typevartuple, | ||
intrinsic_subscript_generic, | ||
intrinsic_typealias | ||
]) |
40 changes: 40 additions & 0 deletions
40
sdks/python/apache_beam/typehints/intrinsic_one_ops_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""Tests for apache_beam.typehints.intrinsic_one_ops.""" | ||
|
||
# pytype: skip-file | ||
|
||
import dis | ||
import sys | ||
import unittest | ||
|
||
from apache_beam.typehints import intrinsic_one_ops | ||
|
||
|
||
class IntrinsicOneOpsTest(unittest.TestCase): | ||
def test_unary_intrinsic_ops_are_in_the_same_order_as_in_cpython(self): | ||
if sys.version_info >= (3, 12): | ||
dis_order = dis.__dict__['_intrinsic_1_descs'] | ||
beam_ops = [fn.__name_upper() for fn in intrinsic_one_ops.INT_ONE_OPS] | ||
for fn in intrinsic_one_ops.INT_ONE_OPS: | ||
beam_ops.append(fn.__name__.upper()) | ||
self.assertListEqual(dis_order, beam_ops) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters