python / python/cpython

Strange 3.14.0a1 problem in attribute assignment

未关闭
#125,968 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:
		# bold, italic
		_ = tt2ps(frag.fontName,frag.bold,frag.italic)
		if _=='helvetica': breakpoint()
		frag.fontName = _
		if frag.fontName=='helvetica': breakpoint()

the code above breaks at the second breakpoint. The value of _ is 'Helvetica', but the attribute value is 'helvetica' (the original value). It's not clear if the assignment is carried out or somehow transformed to lower case. The frag class is ParaFrag(ABag): pass with ABag defined as

class ABag:
	"""
	'Attribute Bag' - a trivial BAG class for holding attributes.

	This predates modern Python.  Doing this again, we'd use a subclass
	of dict.

	You may initialize with keyword arguments.
	a = ABag(k0=v0,....,kx=vx,....) ==> getattr(a,'kx')==vx

	c = a.clone(ak0=av0,.....) copy with optional additional attributes.
	"""
	def __init__(self,**attr):
		self.__dict__.update(attr)

	def clone(self,**attr):
		n = self.__class__(**self.__dict__)
		if attr: n.__dict__.update(attr)
		return n

	def __repr__(self):
		D = self.__dict__
		K = list(D.keys())
		K.sort()
		return '%s(%s)' % (self.__class__.__name__,', '.join(['%s=%r' % (k,D[k]) for k in K]))

the _ intermediate variable is not actually used in the original code, but the original and this code works as expected in python 3.9-3.13.

Original code is https://hg.reportlab.com/hg-public/reportlab/file/tip/src/reportlab/platypus/paraparser.py (line 3131) and https://hg.reportlab.com/hg-public/reportlab/file/tip/src/reportlab/lib/abag.py

CPython versions tested on:

3.14

Operating systems tested on:

Linux

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用 reportlab 的 src/reportlab/platypus/paraparser.py 第 3131 行附近的代码以及 src/reportlab/lib/abag.py,在 Python 3.14 和较早版本上重现报告中的行为。比较属性赋值行为,并确定该报告是否记录了 CPython 回归;完成的标准是确定原因并记录或实现适当的解决方案。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。