In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Python3.6 how to add type comments to verify the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you will have something to gain after reading this Python3.6 how to add type comments verification article, let's take a look at it.
I have a method that uses the _ _ annotations__ dictionary to check that all properties of the class have the correct values. It works well for basic types such as int, str, or bool, but not for more complex elements such as typing. The union or typing. Optional (also an alliance).
The failure is caused by the isinstance () method in the Union object, which throws a TypeError. I can't even find a way to make sure that the comment is a Union, so I can't verify that a value matches a type.
Solution:
The idea, as mentioned in GvR's comments on this issue, is to implement your own version of issubclass/isinstance, using some extra metadata attached to the type:
> > Union [int, str]. _ _ args__ (int, str) > Union [int, str]. _ _ origin__typing.Union
_ _ args__ and _ _ origin__ are available since Python 3.6.3. Probably not in earlier versions, because typing is still temporary.
This is the end of the article on "how to add type annotation verification for Python3.6". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to add type annotations to Python3.6". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.