TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' [duplicate]

 

 

str | None syntax is only supported in 3.10 or later. Use

from typing import Optional
name: Optional[str] = None
For cases where the right hand side isn't None or there are more than two types, you can use Union

from typing import Union
foo: Union[str, int, float] = "bar"

 

posted @   DaisyLinux  阅读(1330)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2022-10-01 Install Elasticsearch with Docker
点击右上角即可分享
微信分享提示