【django项目使用easycython编译】Cannot convert Unicode string to ‘str‘ implicitly.

django项目编译遇到的问题

报错条件

需要编译的python源码里面的函数写了type hint,尤其是return的type hint,

当type hint是str时,但是变量确实f-string格式化后得到的,编译时会报错

报错原因

easycython会检查变量类型,但是f-string格式化后的字符串变量,在cython里面不认为时str类型,不能隐式地编译为str类型

解决问题

  1. 去掉type hint的str
  2. 或者使用str('xxx',encoding='utf-8), 或者 'xxx'.encode('utf-8')显式转为str
相关推荐
金銀銅鐵33 分钟前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 小时前
Agent 流程编排
后端·python·agent
copyer_xyf2 小时前
Agent RAG
后端·python·agent
copyer_xyf2 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf2 小时前
Agent 记忆管理
后端·python·agent
星云穿梭17 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵17 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
黄忠1 天前
大模型之LangGraph技术体系
python·llm
hboot1 天前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780512 天前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python