Open xiaosiyu0603 opened 2 months ago
This is caused by the wildcard import, the use of which is bad practice. If instead you do:
from typing import Literal
This works fine. The underlying problem is that the AST transformer looks for typing.Literal
and special cases it, but as it can't see where Literal
comes from, it doesn't special case Literal
, and ends up removing the quotes.
It works well, thanks a lot! 😀🙏
(It's a little hard for python programmers who lack professional background to discover such mistake.😂 Adding some warnings to the documentation might be helpful.)
I'll think about that. This is a shortcoming of the library though, and it could some day be fixed. It wll involve nontrivial amounts of work though.
Things to check first
[x] I have searched the existing issues and didn't find my bug already reported there
[X] I have checked that my bug is still present in the latest release
Typeguard version
4.3.0
Python version
3.11.5
What happened?
My code:
Exception raised when running in python:
How can we reproduce the bug?
Maybe run the code?