Skip to content

Fix deepcopy(jinja2.Template) raising TypeError#2169

Closed
ShiLiguo123 wants to merge 2 commits into
pallets:mainfrom
ShiLiguo123:fix-template-deepcopy
Closed

Fix deepcopy(jinja2.Template) raising TypeError#2169
ShiLiguo123 wants to merge 2 commits into
pallets:mainfrom
ShiLiguo123:fix-template-deepcopy

Conversation

@ShiLiguo123
Copy link
Copy Markdown

Add copy and deepcopy methods to Template class.

copy returns self (template is immutable).
deepcopy uses object.new to bypass the source requirement.

Fixes #758

ShiLiguo123 and others added 2 commits May 12, 2026 20:41
Add __copy__ and __deepcopy__ methods to the Template class to
support copy.copy() and copy.deepcopy() operations.

- __copy__: Templates are immutable, return self
- __deepcopy__: Use object.__new__ to bypass the constructor's
  required 'source' argument, then deep copy all attributes

Fixes pallets#758
@davidism davidism closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deepcopy(jinja2.Template(...)) raises an exception

2 participants