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

Default to None for generated functions with defaults #422

Closed
asfaltboy opened this issue Mar 14, 2023 · 0 comments · Fixed by #426
Closed

Default to None for generated functions with defaults #422

asfaltboy opened this issue Mar 14, 2023 · 0 comments · Fixed by #426

Comments

@asfaltboy
Copy link

Describe the bug

The python code generator does not allow the caller to skip optional parameters, as it requires every parameter
to be passed as None for these be skipped.

For example, see the code in the tests:

af: edgedb.RelativeDuration | None,
ag: edgedb.DateDuration,
ah: edgedb.DateDuration | None,
ai: edgedb.ConfigMemory,
aj: edgedb.ConfigMemory | None,
ak: edgedb.Range[int],
al: edgedb.Range[int] | None,
am: edgedb.Range[int],
an: edgedb.Range[int] | None,
ao: edgedb.Range[float],
ap: edgedb.Range[float] | None,
aq: edgedb.Range[float],
ar: edgedb.Range[float] | None,
as_: edgedb.Range[datetime.datetime],
at: edgedb.Range[datetime.datetime] | None,
au: edgedb.Range[datetime.datetime],
av: edgedb.Range[datetime.datetime] | None,
aw: edgedb.Range[datetime.date],
ax: edgedb.Range[datetime.date] | None,

This can make "update" calls somewhat cumbersome, as it requires spelling out all fields that are not being updated as None.

Reference discord thread: https://discord.com/channels/841451783728529451/849374935209607199/1081881229676265592

Reproduction

Generate code with edge-py using a query that includes a number of optional parameters.

Expected behavior

I'd like to see something like type | None = None which would bring it in-line with how Typescript parameters work: https://www.edgedb.com/docs/clients/js/parameters#optional-parameters

As a workaround, I created a helper function that copies all parameters from the generated function but defaults to None for the optional arguments.

Versions (please complete the following information):

  • OS: macOS Ventura 13.2.1 (22D68)
  • EdgeDB version: 2.12+a5dfd9f
  • EdgeDB CLI version: 2.3.1+5d93f42
  • edgedb-python version: 1.3.0
  • Python version: 3.10.6

Additional context

Note: I raised another issue related to generated code and enum values here: #419

fantix added a commit that referenced this issue Jun 19, 2024
New Features
============

* Support EdgeDB 5.0 "branch" connection option
  (by @vpetrovykh in #484 #485 #487)

* Support EdgeDB 5.0 AI extension
  (by @fantix in #489 #490)

Breaking Changes
================

* Enum values can now compare to user-defined enums successfully (#425)
  (by @fantix in bb7522c for #419)

* Add optional default to codegen params (#426)
  (by @fantix in 21b024a for #422)

Changes
=======

* blocking client: fix connect and timeout, support IPv6 (#499)
  (by @fantix @zachary822 in 28a83fd for #486)

Fixes
=====

* Add test to check setting a computed global using with_globals. (#494)
  (by @dnwpark in 636bc0e for #494)

* Fix test and add Python 3.12 in CI
  (by @fantix in #498 #503)

* Use result of pydantic_dataclass, will silence linters (#501)
  (by @AdrienPensart in d88187a)

* Extract ExecuteContext as in/out argument (#500)
  (by @fantix in 2fb7965 for #493)
fantix added a commit that referenced this issue Jun 19, 2024
New Features
============

* Support EdgeDB 5.0 "branch" connection option
  (by @vpetrovykh in #484 #485 #487)

* Support EdgeDB 5.0 AI extension
  (by @fantix in #489 #490)

Breaking Changes
================

* Enum values can now compare to user-defined enums successfully (#425)
  (by @fantix in bb7522c for #419)

* Add optional default to codegen params (#426)
  (by @fantix in 21b024a for #422)

Changes
=======

* blocking client: fix connect and timeout, support IPv6 (#499)
  (by @fantix @zachary822 in 28a83fd for #486)

Fixes
=====

* Add test to check setting a computed global using with_globals. (#494)
  (by @dnwpark in 636bc0e for #494)

* Fix test and add Python 3.12 in CI
  (by @fantix in #498 #503)

* Use result of pydantic_dataclass, will silence linters (#501)
  (by @AdrienPensart in d88187a)

* Extract ExecuteContext as in/out argument (#500)
  (by @fantix in 2fb7965 for #493)
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 a pull request may close this issue.

1 participant