Skip to content

Commit cc7a0d0

Browse files
committed
explicitize args in component meta
1 parent 81fd244 commit cc7a0d0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

dash/development/_py_components_generation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import typing # noqa: F401
2525
import numbers # noqa: F401
2626
from typing_extensions import TypedDict, NotRequired, Literal # noqa: F401
27-
from dash.development.base_component import Component, _explicitize_args
27+
from dash.development.base_component import Component
2828
try:
2929
from dash.development.base_component import ComponentType # noqa: F401
3030
except ImportError:
@@ -80,7 +80,8 @@ def generate_class_string(
8080
_namespace = '{namespace}'
8181
_type = '{typename}'
8282
{shapes}
83-
@_explicitize_args
83+
_explicitize_dash_init = True
84+
8485
def __init__(
8586
self,
8687
{default_argtext}

dash/development/base_component.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ class ComponentMeta(abc.ABCMeta):
5151

5252
# pylint: disable=arguments-differ
5353
def __new__(mcs, name, bases, attributes):
54-
component = abc.ABCMeta.__new__(mcs, name, bases, attributes)
5554
module = attributes["__module__"].split(".")[0]
5655
if name == "Component" or module == "builtins":
5756
# Don't do the base component
5857
# and the components loaded dynamically by load_component
5958
# as it doesn't have the namespace.
60-
return component
59+
return abc.ABCMeta.__new__(mcs, name, bases, attributes)
6160

6261
_namespace = attributes.get("_namespace", module)
6362
ComponentRegistry.namespace_to_package[_namespace] = module
@@ -66,7 +65,13 @@ def __new__(mcs, name, bases, attributes):
6665
"_children_props"
6766
)
6867

69-
return component
68+
if attributes.get("_explicitize_dash_init", False):
69+
# We only want to patch the new generated component without
70+
# the `@_explicitize_args` decorator for mypy support
71+
# See issue: https://github.com/plotly/dash/issues/3226
72+
attributes["__init__"] = _explicitize_args(attributes["__init__"])
73+
74+
return abc.ABCMeta.__new__(mcs, name, bases, attributes)
7075

7176

7277
def is_number(s):
@@ -435,6 +440,8 @@ def _validate_deprecation(self):
435440

436441
ComponentType = typing.TypeVar("ComponentType", bound=Component)
437442

443+
ComponentTemplate = typing.TypeVar("ComponentTemplate")
444+
438445

439446
# This wrapper adds an argument given to generated Component.__init__
440447
# with the actual given parameters by the user as a list of string.

0 commit comments

Comments
 (0)