Switch init pyproject to dulwich#10849
Open
Secrus wants to merge 1 commit intopython-poetry:mainfrom
Open
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- Casting dulwich config values with
str(...)will produce representations like"b'foo'"rather than decoding the underlying bytes; consider decoding with an explicit encoding (e.g.value.decode('utf-8')) before using them in the author string. author_email = str(get_vcs_config_value("user", "email"))will turnNoneinto the string'None', which then passes theif author_email:check and produces" <None>"; guard againstNonebefore converting to string or building the author string.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Casting dulwich config values with `str(...)` will produce representations like `"b'foo'"` rather than decoding the underlying bytes; consider decoding with an explicit encoding (e.g. `value.decode('utf-8')`) before using them in the author string.
- `author_email = str(get_vcs_config_value("user", "email"))` will turn `None` into the string `'None'`, which then passes the `if author_email:` check and produces `" <None>"`; guard against `None` before converting to string or building the author string.
## Individual Comments
### Comment 1
<location path="src/poetry/console/commands/init.py" line_range="149-151" />
<code_context>
if not description and is_interactive:
description = self.ask(self.create_question("Description []: ", default=""))
+ vcs_config = StackedConfig.default()
+
+ def get_vcs_config_value(*keys: str) -> bytes | None:
+ try:
+ value = vcs_config.get(*keys)
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Decode dulwich config values to text instead of returning raw bytes
`StackedConfig.get` returns `bytes`, and the helper currently passes those through, leaving callers to do `str(...)` and ending up with values like `"b'John Doe'"`. Consider decoding here (e.g., UTF-8) and returning `str | None` so downstream code consistently works with text rather than raw bytes.
</issue_to_address>
### Comment 2
<location path="src/poetry/console/commands/init.py" line_range="159-161" />
<code_context>
- if not author and vcs_config.get("user.name"):
- author = vcs_config["user.name"]
- author_email = vcs_config.get("user.email")
+ if not author and (vcs_username := get_vcs_config_value("user", "name")):
+ author = str(vcs_username)
+ author_email = str(get_vcs_config_value("user", "email"))
if author_email:
author += f" <{author_email}>"
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid `str(None)` and potential `b'...'` representations when building the author string
If `get_vcs_config_value(
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Check List
[ ] Added tests for changed code.[ ] Updated documentation for changed code.Switched
initcommand creatingpyproject.tomlconfig to usingdulwichinstead of subprocess-based solution frompoetry-core.