Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Generator now creates types = None in classes for all optional types #1165

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

hellovai
Copy link
Contributor

@hellovai hellovai commented Nov 12, 2024

This was previously breaking literal? types


Important

The PR updates the Python generator to remove default None assignments for optional fields, fixing issues with literal types.

  • Behavior:
    • Updated add_default_value in generate_types.rs to remove default None for optional types.
    • Ensures optional fields in generated Python classes do not have default None values.
  • Files Affected:
    • generate_types.rs: Modified add_default_value function.
    • partial_types.py: Removed default None from optional fields in classes like BigNumbers, BinaryNode, and BlockConstraint.
    • types.py: Removed default None from optional fields in classes like ContactInfo, CustomTaskResult, and Nested.
  • Misc:
    • Fixes issues with literal types being broken by default None assignments.

This description was created by Ellipsis for e467f07. It will automatically update as commits are pushed.

… types

This was previously breaking literal? types
Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 12, 2024 8:39am

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to e467f07 in 53 seconds

More details
  • Looked at 579 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_aAbzK8jPiYiviPWn


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -160,11 +160,11 @@ impl<'ir> From<ClassWalker<'ir>> for PartialPythonClass<'ir> {
}
}

pub fn add_default_value(node: &FieldType, type_str: &String) -> String {
if type_str.starts_with("Optional[") {
pub fn add_default_value(node: &FieldType, type_str: String) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

The change from &String to String in the add_default_value function signature is unnecessary and can lead to unnecessary cloning. Consider reverting to &String for efficiency.

Suggested change
pub fn add_default_value(node: &FieldType, type_str: String) -> String {
pub fn add_default_value(node: &FieldType, type_str: &String) -> String {

@aaronvg
Copy link
Contributor

aaronvg commented Dec 17, 2024

note for the future, we cant merge this since we need default None types or anyone using these models with fastapi or whatnot will get exceptions (fastapi requires default None types for all optionals)

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.

2 participants