Skip to content

Better type Module.apply signature - PR discussion #4779

Open

Description

@Daraan

Following up on #2086 and this recent SO question How to type hint flax.linen.Module.apply's output correctly?.

I would like to add a PR based on my answer and add two typing.overload signatures that make it more clear when to expect a tuple return value - following the contribution guidelines I am opening this issue first.

Based on #2086, the docstring and

flax/flax/core/scope.py

Lines 1080 to 1083 in 893a660

if mutable is not False:
return y, root.mutable_variables()
else:
return y

I am certain that only mutable=False never returns a tuple, otherwise it will always be a tuple.

Activity

  1. changed the title [-]Better type Module.apply signature[/-] [+]Better type Module.apply signature - PR discussion[/+] on Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions