【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
相关推荐
芝士爱知识a6 分钟前
【FinTech前沿】重塑衍生品交易:十维深度解析 AlphaGBM 智能期权分析平台
人工智能·python·量化交易·期权分析·alphagbm·期权交易·ai期权
小白菜又菜43 分钟前
Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
python·算法·leetcode
Omigeq1 小时前
1.2.2 - 采样搜索算法(以RRT和RRT*为例) - Python运动规划库教程(Python Motion Planning)
开发语言·人工智能·python·机器人
凌云拓界1 小时前
TypeWell全攻略(二):热力图渲染引擎,让键盘发光
前端·后端·python·计算机外设·交互·pyqt·数据可视化
小白菜又菜1 小时前
Leetcode 234. Palindrome Linked List
python·算法·leetcode
恒云客1 小时前
python uv debug launch.json
数据库·python·json
Katecat996631 小时前
YOLO11-SEG-AFPN-P345改进采血装置检测与识别系统
python
q1234567890982 小时前
FNN sin predict
开发语言·python
先做个垃圾出来………2 小时前
Python字节串“b“前缀
开发语言·python
dreams_dream2 小时前
什么是迭代器和生成器
python