Skip to content

Commit 2cdbb83

Browse files
authored
Merge pull request #3239 from plotly/fix/stringcase
Remove stringcase
2 parents a8ad575 + 2179158 commit 2cdbb83

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [UNRELEASED]
6+
7+
## Fixed
8+
9+
- [#3239](https://github.com/plotly/dash/pull/3239) Remove stringcase dependency, fix [#3238](https://github.com/plotly/dash/issues/3238)
10+
511
## [3.0.0] - 2025-03-17
612

713
## Added

dash/_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import secrets
1212
import string
1313
import inspect
14+
import re
15+
1416
from html import escape
1517
from functools import wraps
1618
from typing import Union
@@ -302,3 +304,14 @@ def get_caller_name():
302304
return s.frame.f_locals.get("__name__", "__main__")
303305

304306
return "__main__"
307+
308+
309+
def pascal_case(name: Union[str, None]):
310+
s = re.sub(r"\s", "_", str(name))
311+
# Replace leading `_`
312+
s = re.sub("^[_]+", "", s)
313+
if not s:
314+
return s
315+
return s[0].upper() + re.sub(
316+
r"[\-_\.]+([a-z])", lambda match: match.group(1).upper(), s[1:]
317+
)

dash/development/_py_prop_typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import textwrap
55
import importlib
66

7-
import stringcase
7+
from .._utils import pascal_case
88

99

1010
shapes = {}
@@ -54,7 +54,7 @@ def generate_any(*_):
5454

5555
def generate_shape(type_info, component_name: str, prop_name: str):
5656
props = []
57-
name = stringcase.pascalcase(prop_name)
57+
name = pascal_case(prop_name)
5858

5959
for prop_key, prop_type in type_info["value"].items():
6060
typed = get_prop_typing(

dash/py.typed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
partial

requirements/install.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ requests
77
retrying
88
nest-asyncio
99
setuptools
10-
stringcase>=1.2.0

tests/unit/library/test_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,19 @@ def test_ddut001_attribute_dict():
5858
a.x = 4
5959
assert err.value.args == ("Object is final: No new keys may be added.", "x")
6060
assert "x" not in a
61+
62+
63+
@pytest.mark.parametrize(
64+
"value,expected",
65+
[
66+
("foo_bar", "FooBar"),
67+
("", ""),
68+
("fooBarFoo", "FooBarFoo"),
69+
("foo bar", "FooBar"),
70+
("foo-bar", "FooBar"),
71+
("__private_prop", "PrivateProp"),
72+
("double__middle___triple", "DoubleMiddleTriple"),
73+
],
74+
)
75+
def test_ddut002_pascal_case(value, expected):
76+
assert utils.pascal_case(value) == expected

0 commit comments

Comments
 (0)