【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
相关推荐
郭庆汝27 分钟前
pytorch、torchvision与python版本对应关系
人工智能·pytorch·python
思则变3 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
漫谈网络4 小时前
WebSocket 在前后端的完整使用流程
javascript·python·websocket
try2find5 小时前
安装llama-cpp-python踩坑记
开发语言·python·llama
博观而约取6 小时前
Django ORM 1. 创建模型(Model)
数据库·python·django
精灵vector8 小时前
构建专家级SQL Agent交互
python·aigc·ai编程
Zonda要好好学习8 小时前
Python入门Day2
开发语言·python
小王子10248 小时前
Django+DRF 实战:从异常捕获到自定义错误信息
后端·django·web开发
Vertira8 小时前
pdf 合并 python实现(已解决)
前端·python·pdf