Skip to content

Commit ba9e24a

Browse files
levskayaFlax Authors
authored andcommitted
undo recent typing changes as it may be confusing pyright
PiperOrigin-RevId: 559463753
1 parent 7927774 commit ba9e24a

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

flax/linen/module.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -873,10 +873,6 @@ def __getattr__(self, name):
873873
# -----------------------------------------------------------------------------
874874

875875

876-
def module_field(*, kw_only: bool = False, default: Optional[Any] = ...) -> Any:
877-
...
878-
879-
880876
# The ModuleBase class is created only to make static analyzers happy
881877
# mainly pytype and pyright. Some notes:
882878
# * pyright (correctly) complains that Module itself is not a dataclass, even
@@ -891,12 +887,14 @@ def module_field(*, kw_only: bool = False, default: Optional[Any] = ...) -> Any:
891887
# * Other attributes are annotated for completeness. Because we are using
892888
# the `if typing.TYPE_CHECKING` pattern, these annotations are not present
893889
# at runtime so they don't affect the dataclass behavior.
894-
@dataclass_transform(field_specifiers=(module_field,)) # type: ignore[literal-required]
890+
@dataclass_transform()
895891
class ModuleBase:
896892
if typing.TYPE_CHECKING:
893+
name: Optional[str] = None
897894
scope: Optional[Scope]
898895
_state: _ModuleInternalState
899896
_parent_ref: Union['Module', weakref.ReferenceType['Module'], None]
897+
parent: Union['Module', _Sentinel, None]
900898
__dataclass_fields__: Dict[str, dataclasses.Field]
901899

902900

@@ -936,10 +934,6 @@ def __call__(self, x):
936934
"""
937935

938936
if typing.TYPE_CHECKING:
939-
name: Optional[str] = module_field(kw_only=True, default=None)
940-
parent: Union['Module', _Sentinel, None] = module_field(
941-
kw_only=True, default=None
942-
)
943937

944938
def __init__(self, *args, **kwargs):
945939
# this stub makes sure pytype accepts constructor arguments.

0 commit comments

Comments
 (0)