Skip to content

Commit 99faab8

Browse files
committed
Add argument misc.tname(include_module=False)
1 parent 62ad44a commit 99faab8

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Argument `include_module=False` for function `misc.tname()`.
1012

1113
### Removed
12-
* Module `rics.ml.time_split`. use the `time-split` [![PyPI - Version](https://img.shields.io/pypi/v/time-split.svg)](https://pypi.python.org/pypi/time-split) package instead.
14+
- Module `rics.ml.time_split`. use the `time-split` [![PyPI - Version](https://img.shields.io/pypi/v/time-split.svg)](https://pypi.python.org/pypi/time-split) package instead.
1315

1416
## [4.1.1] - 2024-06-29
1517

@@ -19,19 +21,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1921
## [4.1.0] - 2024-05-25
2022

2123
### Added
22-
* New module `rics.paths`; `paths.parse_any_path()`, derived functions `any_path_to_str()` and `any_path_to_path()`.
23-
* New module `rics.strings`. Moved `format_perf_counter()` and `format_seconds()`.
24-
* New function `strings.format_bytes()`.
25-
* New function `rics.collections.dicts.format_changed_keys()`.
24+
- New module `rics.paths`; `paths.parse_any_path()`, derived functions `any_path_to_str()` and `any_path_to_path()`.
25+
- New module `rics.strings`. Moved `format_perf_counter()` and `format_seconds()`.
26+
- New function `strings.format_bytes()`.
27+
- New function `rics.collections.dicts.format_changed_keys()`.
2628

2729
### Deprecated
28-
* Module `rics.ml.time_split`. use the `time-split` [![PyPI - Version](https://img.shields.io/pypi/v/time-split.svg)](https://pypi.python.org/pypi/time-split) package instead.
29-
* Functions `rics.performance.format_perf_counter()` and `format_seconds()`. Use `rics.strings`-functions instead.
30+
- Module `rics.ml.time_split`. use the `time-split` [![PyPI - Version](https://img.shields.io/pypi/v/time-split.svg)](https://pypi.python.org/pypi/time-split) package instead.
31+
- Functions `rics.performance.format_perf_counter()` and `format_seconds()`. Use `rics.strings`-functions instead.
3032

3133
## [4.0.1] - 2024-03-21
3234

3335
### Fixed
34-
* Fix RTD build. Docs for `4.0.0` are not available, but `4.0.1` docs are identical.
36+
- Fix RTD build. Docs for `4.0.0` are not available, but `4.0.1` docs are identical.
3537

3638
## [4.0.0] - 2024-03-21
3739

tests/test_misc/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def __init__(self, n: int = 1):
99
self.n = n
1010

1111
class Bar:
12-
pass
12+
def inner_bar(self):
13+
pass
1314

1415
@classmethod
1516
def bar(cls) -> str:

tests/test_misc/test_tname.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
(say_hi, "say_hi"),
2121
(Foo.Bar, "Foo.Bar"),
2222
(Foo.Bar(), "Foo.Bar"),
23+
(Foo.Bar.inner_bar, "Foo.Bar.inner_bar"),
24+
(Foo.Bar().inner_bar, "Foo.Bar.inner_bar"),
25+
(Foo().Bar.inner_bar, "Foo.Bar.inner_bar"),
26+
(Foo().Bar().inner_bar, "Foo.Bar.inner_bar"),
2327
],
2428
)
2529
class Test:
@@ -31,6 +35,17 @@ def test_without_class(self, obj, expected):
3135
def test_with_class(self, obj, expected):
3236
assert misc.tname(obj, prefix_classname=True) == expected
3337

38+
def test_include_module(self, obj, expected):
39+
actual = misc.tname(obj, include_module=True, prefix_classname=True)
40+
if obj is None:
41+
assert actual == expected
42+
return
43+
if isinstance(obj, str):
44+
assert actual == "builtins.str"
45+
return
46+
47+
assert actual == "tests.test_misc.data." + expected
48+
3449
@pytest.mark.parametrize("n_wraps", [1, 2, 4])
3550
def test_wrapped(self, obj, expected, n_wraps):
3651
class Wrapper:

0 commit comments

Comments
 (0)