Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@niupilot
Copy link
Contributor

@niupilot niupilot bot commented Oct 11, 2025

Summary

  • Added comprehensive documentation for keyword arguments (kwargs) feature
  • Included practical examples demonstrating kwargs with maps, structs, and variadic parameters
  • Updated Table of Contents to include new section

Related Issue

Closes #2443

Documentation Changes

  • New section "Keyword arguments" added after "Variadic parameters"
  • Three subsections covering different use cases:
    • Using kwargs with maps
    • Using kwargs with structs
    • Combining with variadic parameters
  • Clear examples showing both uppercase and lowercase field name syntax
  • Key rules and best practices documented

Generated with codeagent

- Added comprehensive documentation for kwargs feature
- Included examples with maps, structs, and variadic parameters
- Updated Table of Contents
- Related to #2443

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: niupilot <[email protected]>
@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.33%. Comparing base (8814a70) to head (c39c696).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2456   +/-   ##
=======================================
  Coverage   93.33%   93.33%           
=======================================
  Files          34       34           
  Lines       11608    11608           
=======================================
  Hits        10834    10834           
  Misses        609      609           
  Partials      165      165           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@xushiwei xushiwei left a comment

Choose a reason for hiding this comment

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

@niupilot please check review comments

* [Returning multiple values](#returning-multiple-values)
* [Optional parameters](#optional-parameters)
* [Variadic parameters](#variadic-parameters)
* [Keyword arguments](#keyword-arguments)
Copy link
Member

Choose a reason for hiding this comment

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

put document related Keyword arguments before Variadic parameters

doc/docs.md Outdated
```

**Key rules:**
- Named parameters must come after positional parameters when calling functions
Copy link
Member

Choose a reason for hiding this comment

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

Let's unify the terminology. Instead of calling it named parameter and kwargs parameter, we will call it keyword parameter.

doc/docs.md Outdated
- Named parameters must come after positional parameters when calling functions
- The kwargs parameter must be the last parameter (without variadic) or second-to-last (with variadic)
- Parameter names in function calls can use either lowercase or uppercase for struct fields
- Use `T?` syntax to make kwargs parameters optional (defaults to zero value)
Copy link
Member

Choose a reason for hiding this comment

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

Key rules:

  • The keyword parameter must be a optional parameter.
  • The keyword parameter must be the last parameter (without variadic) or second-to-last (with variadic).
  • When calling a function, keyword arguments must be placed after all normal parameters (including optional parameters). This might seem inconsistent with the order of optional and optional parameters in a function declaration, but that's the rule.

Copy link
Member

Choose a reason for hiding this comment

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

@niupilot Please update the previous examples to conform to these rules.

Copy link
Contributor Author

@niupilot niupilot bot Oct 11, 2025

Choose a reason for hiding this comment

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

Examples Updated ✅

Successfully updated all examples to conform to the keyword parameter rules.

Changes made:

  • ✅ Fixed process() example - moved variadic args before keyword args: process("extra", 1, name="Ken", age=17)
  • ✅ Fixed connect() example - moved variadic args before keyword args: connect("ssl", "verify", host="example.com", port=443)
  • ✅ Updated comments to clarify the correct order

All examples now comply with the rule: keyword arguments must be placed after all normal parameters (including optional parameters).

Commit: 1929534


Job run: https://github.com/goplus/xgo/actions/runs/...

@niupilot
Copy link
Contributor Author

niupilot bot commented Oct 11, 2025

Review Comments Addressed ✅

Successfully implemented all feedback from @xushiwei's review:

Changes made:

  1. ✅ Moved keyword arguments section before variadic parameters section
  2. ✅ Unified terminology throughout - replaced "named parameter" and "kwargs parameter" with "keyword parameter"
  3. ✅ Updated key rules section with the specific requirements:
    • The keyword parameter must be an optional parameter
    • The keyword parameter must be the last parameter (without variadic) or second-to-last (with variadic)
    • When calling a function, keyword arguments must be placed after all normal parameters (including optional parameters)
  4. ✅ Updated Table of Contents to reflect new section order

Commit: 771688a


Job run: https://github.com/goplus/xgo/actions/runs/...

- Move keyword arguments section before variadic parameters
- Replace terminology: use "keyword parameter" consistently
- Update key rules per @xushiwei's feedback

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: niupilot <[email protected]>
- Move variadic arguments before keyword arguments in function calls
- Update process() example: variadic args now come first
- Update connect() example: variadic args now come first
- Ensure compliance with rule: keyword args must come after all positional params

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: niupilot <[email protected]>
Copy link
Member

@xushiwei xushiwei left a comment

Choose a reason for hiding this comment

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

@niupilot check review comments

doc/docs.md Outdated
```go
func process(opts map[string]any?, args ...any) {
if name, ok := opts["name"]; ok {
println "Name:", name
Copy link
Member

Choose a reason for hiding this comment

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

use echo instead of println. please check the whole quick start and replace them.

doc/docs.md Outdated
City string
}

func configure(opts *Options?) {
Copy link
Member

Choose a reason for hiding this comment

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

opts can be nil, it will crash when accessing opts.Name

doc/docs.md Outdated
configure() // optional parameter with zero value
```

#### Combining with variadic parameters
Copy link
Member

Choose a reason for hiding this comment

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

remove this section.

@niupilot
Copy link
Contributor Author

niupilot bot commented Oct 11, 2025

Review Comments Addressed ✅

Successfully implemented all feedback from @xushiwei's latest review:

Changes made:

  1. Replaced println with echo - Updated all 6 instances in the keyword arguments section to use echo instead of println

  2. Fixed nil pointer crash - Added nil check in configure function:

    func configure(opts *Options?) {
        if opts != nil {
            echo "Name:", opts.Name
            echo "Age:", opts.Age
            echo "City:", opts.City
        }
    }
  3. Removed "Combining with variadic parameters" section - Removed the entire subsection as requested, including all example code

Commit: 192bcd1


Job run: https://github.com/goplus/xgo/actions/runs/...

- Replace println with echo throughout keyword arguments section
- Add nil check in configure function to prevent crash
- Remove "Combining with variadic parameters" subsection

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: niupilot <[email protected]>
doc/docs.md Outdated
City string
}

func configure(opts *Options?) {
Copy link
Member

Choose a reason for hiding this comment

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

@niupilot This is not a good example. Name and Age are not optional in common case. Please change an example.

Copy link
Contributor Author

@niupilot niupilot bot Oct 11, 2025

Choose a reason for hiding this comment

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

Example Improved ✅

Successfully updated the struct example with more appropriate, naturally optional fields.

Changes made:

  1. Replaced struct fields - Changed from Name, Age, City to Timeout, MaxRetries, Debug

    • These are configuration options that are naturally optional in common use cases
  2. Updated function logic - Changed from configure() to run() with proper default handling:

    • Default timeout: 30
    • Default maxRetries: 3
    • Default debug: false
  3. Better demonstrates the feature - The new example shows:

    • How optional configuration parameters work in practice
    • Proper nil checking and default value fallbacks
    • Both lowercase and uppercase field name syntax
    • Zero-value defaults when no parameters provided

Example now shows:

run(timeout=60, maxRetries=5)    // partial configuration
run(Timeout=10, Debug=true)       // different subset of options
run()                             // uses all defaults

Commit: ad21525


Job run: https://github.com/goplus/xgo/actions/runs/...

- Replace Options struct with Config struct
- Use configuration fields (Timeout, MaxRetries, Debug) that are naturally optional
- Add proper default value handling in the function
- More realistic example that demonstrates optional parameters effectively

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: niupilot <[email protected]>
doc/docs.md Outdated
**Key rules:**
- The keyword parameter must be an optional parameter.
- The keyword parameter must be the last parameter (without variadic) or second-to-last (with variadic).
- When calling a function, keyword arguments must be placed after all normal parameters (including optional parameters). This might seem inconsistent with the order of optional and variadic parameters in a function declaration, but that's the rule.
Copy link
Member

Choose a reason for hiding this comment

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

@niupilot Sorry, I made a mistake earlier, please correct it to this: When calling a function, keyword arguments must be placed after all normal parameters (including variadic parameters). This might seem inconsistent with the order of keyword and variadic parameters in a function declaration, but that's the rule.

Copy link
Contributor Author

@niupilot niupilot bot Oct 11, 2025

Choose a reason for hiding this comment

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

Key Rules Text Corrected ✅

Successfully updated the rule text with the corrected version.

Changes made:

  1. Updated rule text - Changed "keyword arguments must be placed after all normal parameters (including optional parameters)" to "keyword arguments must be placed after all normal parameters (including variadic parameters)"

  2. Fixed inconsistency note - Changed "order of optional and variadic parameters" to "order of keyword and variadic parameters"

Corrected rule now reads:

When calling a function, keyword arguments must be placed after all normal parameters (including variadic parameters). This might seem inconsistent with the order of keyword and variadic parameters in a function declaration, but that's the rule.

Commit: c39c696


Job run: https://github.com/goplus/xgo/actions/runs/...

- Correct: "optional parameters" → "variadic parameters"
- Correct: "optional and variadic" → "keyword and variadic"
- Clarify that keyword args must come after variadic params in calls

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: niupilot <[email protected]>
@xushiwei xushiwei merged commit 0c1dbad into main Oct 11, 2025
29 checks passed
@xushiwei xushiwei deleted the codeagent/claude/issue-2443-1760147565 branch October 11, 2025 02:37
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.

keyword arguments (Python-like kwargs syntax)

3 participants