-
See example below. import types
def test(x: types.FunctionType): pass
print(type(test) == types.FunctionType) # True
# Argument of type "(x: FunctionType) -> None"
# cannot be assigned to parameter "x" of type "FunctionType" in function "test"
# "function" is not assignable to "FunctionType"
test(test) The use case - was trying to add typing to old Python 2 code that doesn't have def test_x(x):
# type: (types.FunctionType) -> None
pass
test_x(test_x) |
Beta Was this translation helpful? Give feedback.
Answered by
erictraut
Jan 14, 2025
Replies: 1 comment 3 replies
-
No, this isn't a bug. The types defined in the |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Andrej730
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, this isn't a bug. The types defined in the
types
module should generally not be used for type checking purposes. They represent internal implementation types for Python. You should use types defined in thetyping
module for type annotations instead. In this case, usetyping.Callable
.