Skip to content

Commit

Permalink
Anonymous and the parent does not have sytle_rel
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjkamei committed Aug 31, 2023
1 parent adeb358 commit 29fe8ae
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions weasyprint/css/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,16 @@ class AnonymousStyle():
def __init__(self, parent_style, style_rel):
self.parent_style = parent_style
self.specified = self
self.style_rel = style_rel
if style_rel is not None:
self.style_rel = style_rel
else:
self.style_rel = StyleRelationship()
if parent_style:
self.cache = parent_style.cache
else:
self.cache = {'ratio_ch': {}, 'ratio_ex': {}}

style_rel.set_computed_style(self, None, self, {})
self.style_rel.set_computed_style(self, None, self, {})

# border-*-style is none, so border-width computes to zero.
# Other than that, properties that would need computing are
Expand Down Expand Up @@ -750,7 +753,6 @@ def __init__(self, parent_style, cascaded, element, pseudo_type,
style_rel.set_computed_style(element, pseudo_type, self, {})

def copy(self):
# TODO: Need to modify for flex_layout(Consider sharing "properties")
copy = ComputedStyle(
self.parent_style, self.cascaded, self.element, self.pseudo_type,
self.root_style, self.base_url, self.style_rel)
Expand Down

2 comments on commit 29fe8ae

@Chris2L
Copy link

@Chris2L Chris2L commented on 29fe8ae Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if style_rel is not None:
            self.style_rel = style_rel
        else:
            self.style_rel = StyleRelationship()

This can be

self.style_rel = style_rel or StyleRelationship()

Depending on if this is python version specific and or project style specific, but the above notation is a few microseconds faster.

Also line 669 you added self to style_rel.set_computed_style, should that not be added to line 753 as well?
EDIT:
Okay, maybe not required to add self. Is there a chance that style_rel can be None there as well?

Sorry, not digging into the code much, just loving these updates as it is making a big difference to my reports.

@ssjkamei
Copy link
Author

@ssjkamei ssjkamei commented on 29fe8ae Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be
self.style_rel = style_rel or StyleRelationship()

Indeed it is. I don't usually write code, so I'm glad you pointed that out.

Also line 669 you added self to style_rel.set_computed_style, should that not be added to line 753 as well?

It is certainly more beautiful there. I will make the change. Thanks.

Please sign in to comment.