Skip to content

Switch init pyproject to dulwich#10849

Open
Secrus wants to merge 1 commit intopython-poetry:mainfrom
Secrus:init-author-info
Open

Switch init pyproject to dulwich#10849
Secrus wants to merge 1 commit intopython-poetry:mainfrom
Secrus:init-author-info

Conversation

@Secrus
Copy link
Copy Markdown
Member

@Secrus Secrus commented Apr 18, 2026

Pull Request Check List

  • [ ] Added tests for changed code.
  • [ ] Updated documentation for changed code.

Switched init command creating pyproject.toml config to using dulwich instead of subprocess-based solution from poetry-core.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/poetry/console/commands/init.py
Comment thread src/poetry/console/commands/init.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant