@@ -69,55 +69,45 @@ pip install git+https://github.com/MPCodeWriter21/log21
6969Changelog
7070---------
7171
72- ### v3.3.0
72+ ### v3.3.1
7373
74- Add ` log21.helper_types ` module .
74+ Get rid of ` invalid NoneType value ` error message .
7575
76- This module contains a collection of useful types meant for using with argument parser
77- to parse CLI arguments to more usable formats.
78-
79- + ` FileSize ` : Can take ` str ` and ` int ` values. Will convert human inputs such as "121 KB",
80- "21MiB", or "4.56 GB" to bytes. Can also be used to represent bytes value in more
81- human-readable formats.
82-
83- For even more control you can still define Logger, Handlers, and Formatters manually.
76+ In the previous versions, if you used an optional union type such as ` int | float | None `
77+ which ended with ` None ` , you'd get an error saying ` invalid NoneType value ` that didn't
78+ make any sense to the user. The code has been updated to use the name of the last
79+ non-None type for the error message in these situations.
8480
8581#### Example
8682
8783``` python
88- from pathlib import Path
89-
9084import log21
9185from log21.helper_types import FileSize
9286
9387
94- def main (path : Path, min_size : FileSize, max_size : FileSize, / ):
95- log21.info(
96- " Files that are smaller than %s or bigger than %s will be ignored." ,
97- args = (min_size, max_size),
98- )
99-
100- for file in path.iterdir():
101- if not file .is_file():
102- continue
103- if min_size <= (size := file .stat().st_size) <= max_size:
104- log21.print(
105- " `%s ` is %s ." ,
106- args = (file , FileSize(size).humanize(binary = False , fmt = " %.4f " )),
107- )
108-
88+ def main (min_size : FileSize | None = None , max_size : FileSize | None = None ) -> None :
89+ log21.info(" Min Size: %s , Max Size: %s " , args = (min_size, max_size))
10990
11091if __name__ == " __main__" :
11192 log21.argumentify(main)
11293```
11394
114- Example usage and output :
95+ Before v3.3.1 :
11596
11697``` shell
117- $ uv run test.py . " 1.23MiB" " 0.5 GB"
118- [21:21:21] [INFO] Files that are smaller than 1.23 MiB or bigger than 476.84 MiB will be
119- ignored.
120- ` myfile21.zip` is 35.1856 MB.
98+ $ python test.py -m Hello
99+ usage: test.py [-h] [--min-size MIN_SIZE] [--max-size MAX_SIZE]
100+
101+ test.py: error: argument --min-size/-m: invalid NoneType value: ' Hello'
102+ ```
103+
104+ With v3.3.1 update:
105+
106+ ``` shell
107+ $ python test.py -m Hello
108+ usage: test.py [-h] [--min-size MIN_SIZE] [--max-size MAX_SIZE]
109+
110+ test.py: error: argument --min-size/-m: invalid FileSize value: ' Hello'
121111```
122112
123113[ Full CHANGELOG] ( https://github.com/MPCodeWriter21/log21/blob/master/CHANGELOG.md )
0 commit comments