Skip to content

feat: converter = None as the sentinel#996

Merged
patrick-kidger merged 2 commits intopatrick-kidger:devfrom
nstarman:module-faster-convert
Apr 14, 2025
Merged

feat: converter = None as the sentinel#996
patrick-kidger merged 2 commits intopatrick-kidger:devfrom
nstarman:module-faster-convert

Conversation

@nstarman
Copy link
Contributor

  1. Easier for users to access instead of a private sentinel.
  2. simplifies later performance-related logic changes.
  3. Broadens support to allow dataclasses.field(metadata=dict(converter=None)), not just eqx.field.

Follow up to #994.

@nstarman nstarman marked this pull request as draft April 11, 2025 14:47
@patrick-kidger
Copy link
Owner

Looks reasonable to me! Let's get #994 in and then this one.

@nstarman nstarman force-pushed the module-faster-convert branch from 7569e8f to 20158eb Compare April 14, 2025 13:32
@nstarman nstarman marked this pull request as ready for review April 14, 2025 13:33
@nstarman
Copy link
Contributor Author

@patrick-kidger. Ready!

Copy link
Owner

@patrick-kidger patrick-kidger left a comment

Choose a reason for hiding this comment

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

One comment only, but otherwise LGTM!

for f in dataclasses.fields(cls):
if f.name not in cls.__init__.__annotations__:
continue # Odd behaviour, so skip.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually, I think I'm noticing a bug in the existing code here -- I think we should only be running all of this if has_dataclass_init? Worth fixing up here, if you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Then the check becomes if not f.init: continue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

1. Easier for users to access instead of a private sentinel.
2. simplifies later performance-related logic changes.
3. Broadens support to allow `dataclasses.field(metadata=dict(converter=None))`, not just `eqx.field`.

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
@nstarman nstarman force-pushed the module-faster-convert branch from 20158eb to de28410 Compare April 14, 2025 17:17
Comment on lines +327 to +325
cls.__init__.__annotations__[f.name] = converter_annotation
cls.__init__.__annotations__[f.name] = converter_annotation
Copy link
Owner

@patrick-kidger patrick-kidger Apr 14, 2025

Choose a reason for hiding this comment

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

I think this is an unintentional indent? (Or am I maybe misunderstanding the logic here?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unintentional!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
@nstarman nstarman force-pushed the module-faster-convert branch from de28410 to 7972df3 Compare April 14, 2025 18:53
@patrick-kidger patrick-kidger changed the base branch from main to dev April 14, 2025 19:45
@patrick-kidger patrick-kidger merged commit 2279be8 into patrick-kidger:dev Apr 14, 2025
1 check passed
@patrick-kidger
Copy link
Owner

Okay, great! All looks good me, so merged. :)

Heads-up for other PRs in the near future,I've just spun up a dev branch to merge this into (as changes to main immediately appear in our documentation, and here the eqx.field signature has changed).

@nstarman nstarman deleted the module-faster-convert branch April 14, 2025 20:01
patrick-kidger pushed a commit that referenced this pull request Apr 21, 2025
* feat: converter = None as the sentinel

1. Easier for users to access instead of a private sentinel.
2. simplifies later performance-related logic changes.
3. Broadens support to allow `dataclasses.field(metadata=dict(converter=None))`, not just `eqx.field`.

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

* refactor: only set annotations if datclass init

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

---------

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
patrick-kidger pushed a commit that referenced this pull request May 16, 2025
* feat: converter = None as the sentinel

1. Easier for users to access instead of a private sentinel.
2. simplifies later performance-related logic changes.
3. Broadens support to allow `dataclasses.field(metadata=dict(converter=None))`, not just `eqx.field`.

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

* refactor: only set annotations if datclass init

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

---------

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
patrick-kidger pushed a commit that referenced this pull request Jun 16, 2025
* feat: converter = None as the sentinel

1. Easier for users to access instead of a private sentinel.
2. simplifies later performance-related logic changes.
3. Broadens support to allow `dataclasses.field(metadata=dict(converter=None))`, not just `eqx.field`.

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

* refactor: only set annotations if datclass init

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

---------

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
patrick-kidger pushed a commit that referenced this pull request Jul 7, 2025
* feat: converter = None as the sentinel

1. Easier for users to access instead of a private sentinel.
2. simplifies later performance-related logic changes.
3. Broadens support to allow `dataclasses.field(metadata=dict(converter=None))`, not just `eqx.field`.

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

* refactor: only set annotations if datclass init

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>

---------

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
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