【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
相关推荐
geovindu3 小时前
python: Memento Pattern
开发语言·python·设计模式·备忘录模式
寻星探路4 小时前
【JVM 终极通关指南】万字长文从底层到实战全维度深度拆解 Java 虚拟机
java·开发语言·jvm·人工智能·python·算法·ai
lbb 小魔仙4 小时前
【Java】Java 实战项目:手把手教你写一个电商订单系统
android·java·python
岱宗夫up4 小时前
FastAPI入门(上篇):快速构建高性能Python Web API
开发语言·前端·python·fastapi
Dxy12393102164 小时前
中文乱码恢复方案
开发语言·python
rongyili885 小时前
Dify 外部知识库集成 Milvus 实战指南
开发语言·python·milvus
Hello eveybody5 小时前
什么是动态规划(DP)?(Python版)
python·动态规划
南 阳6 小时前
Python从入门到精通day34
开发语言·python
APIshop7 小时前
阿里巴巴中国站按图搜索1688商品(拍立淘)API 返回值说明
java·python·图搜索算法
哈库纳玛塔塔7 小时前
dbVisitor 利用 queryForPairs 让键值查询一步到位
java·数据库·python