Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up ConsoleOptions.reset_height() by 13% in rich/console.py #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def copy(self) -> "ConsoleOptions":
Returns:
ConsoleOptions: a copy of self.
"""
options: ConsoleOptions = ConsoleOptions.__new__(ConsoleOptions)
options.__dict__ = self.__dict__.copy()
options = ConsoleOptions.__new__(ConsoleOptions)
for attr, value in self.__dict__.items():
setattr(options, attr, value)
return options

def update(
Expand Down Expand Up @@ -235,7 +236,9 @@ def reset_height(self) -> "ConsoleOptions":
Returns:
~ConsoleOptions: New console options instance.
"""
options = self.copy()
options = ConsoleOptions.__new__(ConsoleOptions)
for attr, value in self.__dict__.items():
setattr(options, attr, value)
options.height = None
return options

Expand Down