Skip to content

Commit 9a19862

Browse files
authored
Merge pull request #2748 from xqm32/theme-read-encoding
Added `encoding` parameter in `Theme.read`
2 parents b2f9987 + 0e53bae commit 9a19862

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Added `encoding` parameter in `Theme.read`
13+
14+
815
## [13.2.0] - 2023-01-19
916

1017
### Changed

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ The following people have contributed to the development of Rich:
6060
- [Serkan UYSAL](https://github.com/uysalserkan)
6161
- [Zhe Huang](https://github.com/onlyacat)
6262
- [Ke Sun](https://github.com/ksun212)
63+
- [Qiming Xu](https://github.com/xqm32)

rich/theme.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ def from_file(
5656
return theme
5757

5858
@classmethod
59-
def read(cls, path: str, inherit: bool = True) -> "Theme":
59+
def read(
60+
cls, path: str, inherit: bool = True, encoding: Optional[str] = None
61+
) -> "Theme":
6062
"""Read a theme from a path.
6163
6264
Args:
6365
path (str): Path to a config file readable by Python configparser module.
6466
inherit (bool, optional): Inherit default styles. Defaults to True.
67+
encoding (str, optional): Encoding of the config file. Defaults to None.
6568
6669
Returns:
6770
Theme: A new theme instance.
6871
"""
69-
with open(path, "rt") as config_file:
72+
with open(path, "rt", encoding=encoding) as config_file:
7073
return cls.from_file(config_file, source=path, inherit=inherit)
7174

7275

0 commit comments

Comments
 (0)