Skip to content

Commit e068033

Browse files
fix: argumentify issue replacing falsy default values with None.
1 parent 5aaf8c0 commit e068033

File tree

5 files changed

+109
-82
lines changed

5 files changed

+109
-82
lines changed

CHANGELOG.md

Lines changed: 91 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ Help this project by [Donation](DONATE.md)
66
Changes
77
-------
88

9+
### v3.0.1
10+
11+
Fix the issue with `argumentify` which would result in falsy default values to be
12+
replaced with None.
13+
14+
- Example:
15+
16+
```python
17+
def main(offset: int = 0) -> None:
18+
...
19+
20+
argumentify(main)
21+
```
22+
23+
if no value is provided for `--offset`, the default will be `None` instead of `0` which
24+
is unexpected and can lead to issues.
25+
926
### v3.0.0
1027

1128
This release introduces a cleaned-up internal structure, stricter naming conventions,
@@ -15,158 +32,158 @@ specific exception names**.
1532

1633
#### Breaking Changes
1734

18-
+ **Internal module renaming and normalization**
19-
+ All internal modules were renamed to lowercase and, in some cases, split or
35+
- **Internal module renaming and normalization**
36+
- All internal modules were renamed to lowercase and, in some cases, split or
2037
reorganized.
21-
+ Imports such as `log21.Colors`, `log21.Logger`, `log21.ProgressBar`, etc. are no
38+
- Imports such as `log21.Colors`, `log21.Logger`, `log21.ProgressBar`, etc. are no
2239
longer valid.
23-
+ Users importing from internal modules must update their imports to the new module
40+
- Users importing from internal modules must update their imports to the new module
2441
names.
25-
+ Public imports from `log21` remain supported.
42+
- Public imports from `log21` remain supported.
2643

27-
+ **Argumentify exception renames**
28-
+ Several exceptions were renamed to follow a consistent `*Error` naming convention:
29-
+ `TooFewArguments``TooFewArgumentsError`
30-
+ `RequiredArgument``RequiredArgumentError`
31-
+ `IncompatibleArguments``IncompatibleArgumentsError`
32-
+ Code that explicitly raises or catches these exceptions must be updated.
44+
- **Argumentify exception renames**
45+
- Several exceptions were renamed to follow a consistent `*Error` naming convention:
46+
- `TooFewArguments``TooFewArgumentsError`
47+
- `RequiredArgument``RequiredArgumentError`
48+
- `IncompatibleArguments``IncompatibleArgumentsError`
49+
- Code that explicitly raises or catches these exceptions must be updated.
3350

3451
#### V3 Changes
3552

36-
+ **Crash reporter behavior improvement**
37-
+ Prevented the default file crash reporter from creating `.crash_report` files when it
53+
- **Crash reporter behavior improvement**
54+
- Prevented the default file crash reporter from creating `.crash_report` files when it
3855
is not actually used.
39-
+ Implemented using an internal `FakeModule` helper.
56+
- Implemented using an internal `FakeModule` helper.
4057

41-
+ **Argparse compatibility update**
42-
+ Bundled and used the Python 3.13 `argparse` implementation to ensure consistent
58+
- **Argparse compatibility update**
59+
- Bundled and used the Python 3.13 `argparse` implementation to ensure consistent
4360
behavior across supported Python versions.
4461

45-
+ **Progress bar module rename**
46-
+ Renamed the internal progress bar module to `progress_bar` for consistency with the
62+
- **Progress bar module rename**
63+
- Renamed the internal progress bar module to `progress_bar` for consistency with the
4764
new naming scheme.
48-
+ This will not break the usages of `log21.progress_bar(...)` since the call
65+
- This will not break the usages of `log21.progress_bar(...)` since the call
4966
functionality was added to the module using the `FakeModule` helper.
5067

51-
+ **Examples added and updated**
52-
+ Added new example code files.
53-
+ Updated existing examples to match the v3 API and conventions.
68+
- **Examples added and updated**
69+
- Added new example code files.
70+
- Updated existing examples to match the v3 API and conventions.
5471

5572
#### Fixes
5673

57-
+ Resolved various linting and static-analysis issues across the codebase.
58-
+ Addressed minor compatibility issues uncovered by running linters and pre-commit hooks.
59-
+ Resolved errors occurring in environments with newer versions of argparse.
74+
- Resolved various linting and static-analysis issues across the codebase.
75+
- Addressed minor compatibility issues uncovered by running linters and pre-commit hooks.
76+
- Resolved errors occurring in environments with newer versions of argparse.
6077

6178
#### Internal and Maintenance Changes
6279

63-
+ Migrated the build system configuration to `uv`.
64-
+ Updated Python version classifiers and set the supported Python version to 3.9+.
65-
+ Added `vermin` to the pre-commit configuration.
66-
+ Updated `.gitignore`, license metadata, and tool configurations.
67-
+ Silenced and resolved a large number of linter warnings.
68-
+ General internal refactoring with no intended user-visible behavioral changes.
80+
- Migrated the build system configuration to `uv`.
81+
- Updated Python version classifiers and set the supported Python version to 3.9+.
82+
- Added `vermin` to the pre-commit configuration.
83+
- Updated `.gitignore`, license metadata, and tool configurations.
84+
- Silenced and resolved a large number of linter warnings.
85+
- General internal refactoring with no intended user-visible behavioral changes.
6986

7087
#### Notes
7188

72-
+ There are **no intentional behavioral changes** in logging output, argument parsing
89+
- There are **no intentional behavioral changes** in logging output, argument parsing
7390
logic, or UI components.
74-
+ Most projects will require **minimal or no changes** unless they depend on internal
91+
- Most projects will require **minimal or no changes** unless they depend on internal
7592
modules or renamed exceptions.
76-
+ See [MIGRATION-V2-V3.md](https://github.com/MPCodeWriter21/log21/blob/master/MIGRATION-V2-V3.md)
93+
- See [MIGRATION-V2-V3.md](https://github.com/MPCodeWriter21/log21/blob/master/MIGRATION-V2-V3.md)
7794
for detailed upgrade instructions.
7895

7996
### 2.10.2
8097

81-
+ Update README.md and CHANGELOG.md.
98+
- Update README.md and CHANGELOG.md.
8299

83100
### 2.10.1
84101

85-
+ Updated the Argparse module to be usable with python 3.12.3.
102+
- Updated the Argparse module to be usable with python 3.12.3.
86103

87104
### 2.10.0
88105

89-
+ Added some exception classes to raise in the "argumentified" functions to show
106+
- Added some exception classes to raise in the "argumentified" functions to show
90107
*parser error* to the user: `ArgumentError`, `IncompatibleArguments`,
91108
`RequiredArgument`, `TooFewArguments`
92109

93110
### 2.9.2
94111

95-
+ Added `Sequence[T]` as a supported type to the ColorizingArgumentParser.
96-
+ Bug fixes.
112+
- Added `Sequence[T]` as a supported type to the ColorizingArgumentParser.
113+
- Bug fixes.
97114

98115
### 2.9.1
99116

100-
+ Update `README.md`.
117+
- Update `README.md`.
101118

102119
### 2.9.0
103120

104-
+ Added `<<` and `>>` (left shift and right shift operators) to `log21.Logger.Logger`.
121+
- Added `<<` and `>>` (left shift and right shift operators) to `log21.Logger.Logger`.
105122

106123
### 2.8.1
107124

108-
+ Fixed Carriage Return Handling.
109-
+ Fixed setting level using `log21.basic_config`
110-
+ Added more configuration for developer tools to the `pyproject.toml` file.
111-
+ Added pre-commit.
125+
- Fixed Carriage Return Handling.
126+
- Fixed setting level using `log21.basic_config`
127+
- Added more configuration for developer tools to the `pyproject.toml` file.
128+
- Added pre-commit.
112129

113130
### 2.8.1b0
114131

115-
+ Fixed setting level using `log21.basic_config`
132+
- Fixed setting level using `log21.basic_config`
116133

117134
### 2.8.1a0
118135

119-
+ Fixed Carriage Return Handling.
136+
- Fixed Carriage Return Handling.
120137

121138
### 2.8.0
122139

123-
+ Update python version
124-
+ Renamed `crash_report.log` to `.crash_report.log`.
125-
+ Added "force" error handling method to `Logger.add_level`.
126-
+ Changed the adding level error handling method to "ignore".
127-
+ Ability to add new methods to the Logger object for each custom level.
140+
- Update python version
141+
- Renamed `crash_report.log` to `.crash_report.log`.
142+
- Added "force" error handling method to `Logger.add_level`.
143+
- Changed the adding level error handling method to "ignore".
144+
- Ability to add new methods to the Logger object for each custom level.
128145

129146
### 2.8.0b1
130147

131-
+ Renamed `crash_report.log` to `.crash_report.log`.
148+
- Renamed `crash_report.log` to `.crash_report.log`.
132149

133150
### 2.8.0b0
134151

135-
+ Changed the adding level error handling method to "ignore".
152+
- Changed the adding level error handling method to "ignore".
136153

137154
### 2.8.0a0-2
138155

139-
+ Ability to add new methods to the Logger object for each custom level.
140-
+ Update python version
141-
+ Added "force" error handling method to `Logger.add_level`.
156+
- Ability to add new methods to the Logger object for each custom level.
157+
- Update python version
158+
- Added "force" error handling method to `Logger.add_level`.
142159

143160
### 2.7.1
144161

145-
+ Improved compatibility
162+
- Improved compatibility
146163

147164
### 2.7.0
148165

149-
+ Modified `automatic-release.yml` and `pypi.yml` workflows to check the
166+
- Modified `automatic-release.yml` and `pypi.yml` workflows to check the
150167
version
151-
+ Added the support for more `type`s to pass to
168+
- Added the support for more `type`s to pass to
152169
`ColorizingArgumentParser().add_argument(...)`: `typing.Union`, `typing.Optional`,
153170
`typing.Literal`, `enum.Enum`, `tuple` and `typing.Required`.
154-
+ Modified the way `Enum`s are handled in the Argument Parser.
155-
+ Handled some `typing._SpecialForm`s.
156-
+ A normal ArgumentGroup can now be required! (Unlike MutuallyExclusiveGroup it can
171+
- Modified the way `Enum`s are handled in the Argument Parser.
172+
- Handled some `typing._SpecialForm`s.
173+
- A normal ArgumentGroup can now be required! (Unlike MutuallyExclusiveGroup it can
157174
have more than 1 option used at the same time)
158-
+ `argumentify` now supports async functions as the entry point.
175+
- `argumentify` now supports async functions as the entry point.
159176

160177
### 2.6.2
161178

162179
Change in README.md.
163180

164181
### 2.6.1
165182

166-
+ Added `encoding` to `log21.crash_reporter.FileReporter`.
167-
+ Added configs for `pylint`, `yapf` and `isort` to `pyproject.toml`.
168-
+ Added optional `dev` dependencies to `pyproject.toml`.
169-
+ Improved overall code quality.
183+
- Added `encoding` to `log21.crash_reporter.FileReporter`.
184+
- Added configs for `pylint`, `yapf` and `isort` to `pyproject.toml`.
185+
- Added optional `dev` dependencies to `pyproject.toml`.
186+
- Improved overall code quality.
170187

171188
### 2.6.0
172189

@@ -191,11 +208,11 @@ print(GREEN + 'This' + WHITE + ' is' + RED + ' Red')
191208

192209
Moved some dictionaries to `__init__` methods.
193210

194-
+ `colors` in `Argparse.ColorizingHelpFormatter` class.
195-
+ `_level_name` in `Formatters._Formatter` class and `level_colors` in
211+
- `colors` in `Argparse.ColorizingHelpFormatter` class.
212+
- `_level_name` in `Formatters._Formatter` class and `level_colors` in
196213
`Formatters.ColorizingFormatter` class.
197-
+ `sign_colors` in `PPrint.PrettyPrinter` class.
198-
+ `colors` in `TreePrint.TreePrint.Node` class.
214+
- `sign_colors` in `PPrint.PrettyPrinter` class.
215+
- `colors` in `TreePrint.TreePrint.Node` class.
199216

200217
### 2.5.2
201218

@@ -269,8 +286,8 @@ Bug fixes and improvements.
269286

270287
### 2.4.0
271288

272-
+ Made it more compatible with multi-threading.
273-
+ Fixed some bugs.
289+
- Made it more compatible with multi-threading.
290+
- Fixed some bugs.
274291

275292
### 2.3.10
276293

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,22 @@ pip install git+https://github.com/MPCodeWriter21/log21
6969
Changelog
7070
---------
7171

72-
### v3.0.0
72+
### v3.0.1
7373

74-
This release introduces a cleaned-up internal structure, stricter naming conventions,
75-
and several quality-of-life improvements. While most users will not notice behavioral
76-
changes, **v3 contains breaking changes for code that relies on internal imports or
77-
specific exception names**.
74+
Fix the issue with `argumentify` which would result in falsy default values to be
75+
replaced with None.
76+
77+
+ Example:
78+
79+
```python
80+
def main(offset: int = 0) -> None:
81+
...
82+
83+
argumentify(main)
84+
```
85+
86+
if no value is provided for `--offset`, the default will be `None` instead of `0` which
87+
is unexpected and can lead to issues.
7888

7989
#### Breaking Changes
8090

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies = [
2323
"webcolors",
2424
"docstring-parser"
2525
]
26-
version = "3.0.0"
26+
version = "3.0.1"
2727

2828
[build-system]
2929
requires = ["uv_build>=0.8.15,<0.9.0"]

src/log21/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# yapf: enable
3232

3333
__author__ = 'CodeWriter21 (Mehrad Pooryoussof)'
34-
__version__ = '3.0.0'
34+
__version__ = '3.0.1'
3535
__github__ = 'https://GitHub.com/MPCodeWriter21/log21'
3636
__all__ = [
3737
'ColorizingStreamHandler', 'DecolorizingFileHandler', 'ColorizingFormatter',

src/log21/argumentify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def _add_arguments(
359359
config['required'] = True
360360
if argument.kind == _inspect._ParameterKind.VAR_POSITIONAL:
361361
config['nargs'] = '*'
362-
if argument.default:
362+
if argument.default is not None:
363363
config['default'] = argument.default
364364
parser.add_argument(
365365
*generate_flag(argument, reserved_flags=reserved_flags), **config

0 commit comments

Comments
 (0)