You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, ret is cst.FlattenSentinel[cst.FunctionDef] (an instance of GenericAlias), annotation is libcst._nodes.statement.BaseStatement.
Works as expected without parametrizing the class
Edit: Fails at runtime as well without parametrizing the class:
libcst.matchers._visitors.MatchDecoratorMismatch: Invalid function signature for ForwardRelationOverloadCodemod.mutate_ManyToManyField_FunctionDef: @leave decorated function cannot return the type FlattenSentinel.
Tbh this runtime check of the return annotation is a bit surprising: type hints are not supposed to alter the run time behavior (except when explicitly advertised as is, e.g. like pydantic). It might be worth adding a try..except on this check, and only reraise if the exception is an instance of MatchDecoratorMismatch.
The text was updated successfully, but these errors were encountered:
Viicos
changed the title
FlattenSentinel can't be used as return type annotation when parametrized.FlattenSentinel can't be used as return type annotation
Dec 24, 2023
zsol
added
bug
Something isn't working
machinery
Internal plumbing for visitor, transformer, matcher APIs
labels
Jan 4, 2024
Consider the following code:
This raises the following exception:
TypeError: issubclass() arg 1 must be a class
LibCST/libcst/matchers/_visitors.py
Lines 155 to 157 in 43a27b1
Here,
ret
iscst.FlattenSentinel[cst.FunctionDef]
(an instance ofGenericAlias
),annotation
islibcst._nodes.statement.BaseStatement
.Works as expected without parametrizing the classEdit: Fails at runtime as well without parametrizing the class:
libcst.matchers._visitors.MatchDecoratorMismatch: Invalid function signature for ForwardRelationOverloadCodemod.mutate_ManyToManyField_FunctionDef: @leave decorated function cannot return the type FlattenSentinel.
Tbh this runtime check of the return annotation is a bit surprising: type hints are not supposed to alter the run time behavior (except when explicitly advertised as is, e.g. like
pydantic
). It might be worth adding atry..except
on this check, and only reraise if the exception is an instance ofMatchDecoratorMismatch
.The text was updated successfully, but these errors were encountered: