Skip to content

Commit 0c1badb

Browse files
authored
refactor(java): set class attribute constants (#1)
drop classproperty decorator
1 parent 99fbf02 commit 0c1badb

File tree

2 files changed

+67
-134
lines changed

2 files changed

+67
-134
lines changed

java-api-stubs/stubs/java/util/__init__.pyi

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ from java.util.function import (
1515
ToLongFunction,
1616
)
1717

18-
class classproperty(property):
19-
def __get__(self, cls, owner): ...
20-
2118
class Collection:
2219
def add(self, e: Any) -> bool: ...
2320
def addAll(self, c: Collection) -> bool: ...
@@ -459,30 +456,30 @@ class Locale(Object):
459456
country: Optional[str]
460457
language: str
461458
variant: Optional[str]
459+
CANADA: Locale
460+
CANADA_FRENCH: Locale
461+
CHINA: Locale
462+
CHINESE: Locale
463+
ENGLISH: Locale
464+
FRANCE: Locale
465+
FRENCH: Locale
466+
GERMAN: Locale
467+
GERMANY: Locale
468+
ITALIAN: Locale
469+
ITALY: Locale
470+
JAPAN: Locale
471+
JAPANESE: Locale
472+
KOREA: Locale
473+
KOREAN: Locale
474+
PRC: Locale
475+
SIMPLIFIED_CHINESE: Locale
476+
TAIWAN: Locale
477+
TRADITIONAL_CHINESE: Locale
478+
UK: Locale
479+
US: Locale
462480
def __init__(
463481
self, language: str, country: Optional[str] = ..., variant: Optional[str] = ...
464482
) -> None: ...
465-
def CANADA(self) -> Locale: ...
466-
def CANADA_FRENCH(self) -> Locale: ...
467-
def CHINA(self) -> Locale: ...
468-
def CHINESE(self) -> Locale: ...
469-
def ENGLISH(self) -> Locale: ...
470-
def FRANCE(self) -> Locale: ...
471-
def FRENCH(self) -> Locale: ...
472-
def GERMAN(self) -> Locale: ...
473-
def GERMANY(self) -> Locale: ...
474-
def ITALIAN(self) -> Locale: ...
475-
def ITALY(self) -> Locale: ...
476-
def JAPAN(self) -> Locale: ...
477-
def JAPANESE(self) -> Locale: ...
478-
def KOREA(self) -> Locale: ...
479-
def KOREAN(self) -> Locale: ...
480-
def PRC(self) -> Locale: ...
481-
def SIMPLIFIED_CHINESE(self) -> Locale: ...
482-
def TAIWAN(self) -> Locale: ...
483-
def TRADITIONAL_CHINESE(self) -> Locale: ...
484-
def UK(self) -> Locale: ...
485-
def US(self) -> Locale: ...
486483

487484
class Properties(Hashtable):
488485
def __init__(self, *args: Any) -> None: ...

java-api/src/java/util/__init__.py

Lines changed: 46 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
from java.time import Instant, ZonedDateTime, ZoneId
6767

6868

69-
class classproperty(property): # pylint: disable=invalid-name
70-
def __get__(self, cls, owner): # type: ignore[no-untyped-def]
71-
return classmethod(self.fget).__get__(None, owner)()
72-
73-
7469
class Collection(object):
7570

7671
def add(self, e):
@@ -1275,118 +1270,36 @@ class Locale(Object):
12751270
language = None # type: str
12761271
variant = None # type: Optional[str]
12771272

1273+
# Class attribute constants
1274+
CANADA = None # type: Locale
1275+
CANADA_FRENCH = None # type: Locale
1276+
CHINA = None # type: Locale
1277+
CHINESE = None # type: Locale
1278+
ENGLISH = None # type: Locale
1279+
FRANCE = None # type: Locale
1280+
FRENCH = None # type: Locale
1281+
GERMAN = None # type: Locale
1282+
GERMANY = None # type: Locale
1283+
ITALIAN = None # type: Locale
1284+
ITALY = None # type: Locale
1285+
JAPAN = None # type: Locale
1286+
JAPANESE = None # type: Locale
1287+
KOREA = None # type: Locale
1288+
KOREAN = None # type: Locale
1289+
PRC = None # type: Locale
1290+
SIMPLIFIED_CHINESE = None # type: Locale
1291+
TAIWAN = None # type: Locale
1292+
TRADITIONAL_CHINESE = None # type: Locale
1293+
UK = None # type: Locale
1294+
US = None # type: Locale
1295+
12781296
def __init__(self, language, country=None, variant=None):
12791297
# type: (str, Optional[str], Optional[str]) -> None
12801298
super(Locale, self).__init__()
12811299
self.language = language
12821300
self.country = country
12831301
self.variant = variant
12841302

1285-
@classproperty
1286-
def CANADA(self):
1287-
# type: () -> Locale
1288-
return Locale("en", "CA")
1289-
1290-
@classproperty
1291-
def CANADA_FRENCH(self):
1292-
# type: () -> Locale
1293-
return Locale("fr", "CA")
1294-
1295-
@classproperty
1296-
def CHINA(self):
1297-
# type: () -> Locale
1298-
return Locale("zh", "CN")
1299-
1300-
@classproperty
1301-
def CHINESE(self):
1302-
# type: () -> Locale
1303-
return Locale("zh")
1304-
1305-
@classproperty
1306-
def ENGLISH(self):
1307-
# type: () -> Locale
1308-
return Locale("en")
1309-
1310-
@classproperty
1311-
def FRANCE(self):
1312-
# type: () -> Locale
1313-
return Locale("fr", "FR")
1314-
1315-
@classproperty
1316-
def FRENCH(self):
1317-
# type: () -> Locale
1318-
return Locale("fr")
1319-
1320-
@classproperty
1321-
def GERMAN(self):
1322-
# type: () -> Locale
1323-
return Locale("de")
1324-
1325-
@classproperty
1326-
def GERMANY(self):
1327-
# type: () -> Locale
1328-
return Locale("de", "DE")
1329-
1330-
@classproperty
1331-
def ITALIAN(self):
1332-
# type: () -> Locale
1333-
return Locale("it")
1334-
1335-
@classproperty
1336-
def ITALY(self):
1337-
# type: () -> Locale
1338-
return Locale("it", "IT")
1339-
1340-
@classproperty
1341-
def JAPAN(self):
1342-
# type: () -> Locale
1343-
return Locale("ja", "JP")
1344-
1345-
@classproperty
1346-
def JAPANESE(self):
1347-
# type: () -> Locale
1348-
return Locale("ja")
1349-
1350-
@classproperty
1351-
def KOREA(self):
1352-
# type: () -> Locale
1353-
return Locale("ko", "KR")
1354-
1355-
@classproperty
1356-
def KOREAN(self):
1357-
# type: () -> Locale
1358-
return Locale("ko")
1359-
1360-
@classproperty
1361-
def PRC(self):
1362-
# type: () -> Locale
1363-
return Locale("zh", "CN")
1364-
1365-
@classproperty
1366-
def SIMPLIFIED_CHINESE(self):
1367-
# type: () -> Locale
1368-
return Locale("zh", "CN")
1369-
1370-
@classproperty
1371-
def TAIWAN(self):
1372-
# type: () -> Locale
1373-
return Locale("zh", "TW")
1374-
1375-
@classproperty
1376-
def TRADITIONAL_CHINESE(self):
1377-
# type: () -> Locale
1378-
return Locale("zh", "TW")
1379-
1380-
@classproperty
1381-
def UK(self):
1382-
# type: () -> Locale
1383-
return Locale("en", "GB")
1384-
1385-
@classproperty
1386-
def US(self):
1387-
# type: () -> Locale
1388-
return Locale("en", "US")
1389-
13901303
def __str__(self):
13911304
# type: () -> str
13921305
ret = self.language
@@ -1401,6 +1314,29 @@ def __repr__(self):
14011314
return "{!r}".format(self.__str__())
14021315

14031316

1317+
Locale.CANADA = Locale("en", "CA")
1318+
Locale.CANADA_FRENCH = Locale("fr", "CA")
1319+
Locale.CHINA = Locale("zh", "CN")
1320+
Locale.CHINESE = Locale("zh")
1321+
Locale.ENGLISH = Locale("en")
1322+
Locale.FRANCE = Locale("fr", "FR")
1323+
Locale.FRENCH = Locale("fr")
1324+
Locale.GERMAN = Locale("de")
1325+
Locale.GERMANY = Locale("de", "DE")
1326+
Locale.ITALIAN = Locale("it")
1327+
Locale.ITALY = Locale("it", "IT")
1328+
Locale.JAPAN = Locale("ja", "JP")
1329+
Locale.JAPANESE = Locale("ja")
1330+
Locale.KOREA = Locale("ko", "KR")
1331+
Locale.KOREAN = Locale("ko")
1332+
Locale.PRC = Locale("zh", "CN")
1333+
Locale.SIMPLIFIED_CHINESE = Locale("zh", "CN")
1334+
Locale.TAIWAN = Locale("zh", "TW")
1335+
Locale.TRADITIONAL_CHINESE = Locale("zh", "TW")
1336+
Locale.UK = Locale("en", "GB")
1337+
Locale.US = Locale("en", "US")
1338+
1339+
14041340
class Properties(Hashtable):
14051341
def __init__(self, *args):
14061342
# type: (*Any) -> None

0 commit comments

Comments
 (0)