From 2a6f1e5e899e7cf3e68911bb9ee6ef1fcbe8c559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Rom=C3=A1n?= Date: Fri, 5 Dec 2025 23:46:32 -0800 Subject: [PATCH] refactor(java): set class attribute constants drop classproperty decorator --- java-api-stubs/stubs/java/util/__init__.pyi | 45 +++--- java-api/src/java/util/__init__.py | 156 ++++++-------------- 2 files changed, 67 insertions(+), 134 deletions(-) diff --git a/java-api-stubs/stubs/java/util/__init__.pyi b/java-api-stubs/stubs/java/util/__init__.pyi index bb35294..8a56fad 100644 --- a/java-api-stubs/stubs/java/util/__init__.pyi +++ b/java-api-stubs/stubs/java/util/__init__.pyi @@ -15,9 +15,6 @@ from java.util.function import ( ToLongFunction, ) -class classproperty(property): - def __get__(self, cls, owner): ... - class Collection: def add(self, e: Any) -> bool: ... def addAll(self, c: Collection) -> bool: ... @@ -459,30 +456,30 @@ class Locale(Object): country: Optional[str] language: str variant: Optional[str] + CANADA: Locale + CANADA_FRENCH: Locale + CHINA: Locale + CHINESE: Locale + ENGLISH: Locale + FRANCE: Locale + FRENCH: Locale + GERMAN: Locale + GERMANY: Locale + ITALIAN: Locale + ITALY: Locale + JAPAN: Locale + JAPANESE: Locale + KOREA: Locale + KOREAN: Locale + PRC: Locale + SIMPLIFIED_CHINESE: Locale + TAIWAN: Locale + TRADITIONAL_CHINESE: Locale + UK: Locale + US: Locale def __init__( self, language: str, country: Optional[str] = ..., variant: Optional[str] = ... ) -> None: ... - def CANADA(self) -> Locale: ... - def CANADA_FRENCH(self) -> Locale: ... - def CHINA(self) -> Locale: ... - def CHINESE(self) -> Locale: ... - def ENGLISH(self) -> Locale: ... - def FRANCE(self) -> Locale: ... - def FRENCH(self) -> Locale: ... - def GERMAN(self) -> Locale: ... - def GERMANY(self) -> Locale: ... - def ITALIAN(self) -> Locale: ... - def ITALY(self) -> Locale: ... - def JAPAN(self) -> Locale: ... - def JAPANESE(self) -> Locale: ... - def KOREA(self) -> Locale: ... - def KOREAN(self) -> Locale: ... - def PRC(self) -> Locale: ... - def SIMPLIFIED_CHINESE(self) -> Locale: ... - def TAIWAN(self) -> Locale: ... - def TRADITIONAL_CHINESE(self) -> Locale: ... - def UK(self) -> Locale: ... - def US(self) -> Locale: ... class Properties(Hashtable): def __init__(self, *args: Any) -> None: ... diff --git a/java-api/src/java/util/__init__.py b/java-api/src/java/util/__init__.py index f02cf69..6fba882 100644 --- a/java-api/src/java/util/__init__.py +++ b/java-api/src/java/util/__init__.py @@ -66,11 +66,6 @@ from java.time import Instant, ZonedDateTime, ZoneId -class classproperty(property): # pylint: disable=invalid-name - def __get__(self, cls, owner): # type: ignore[no-untyped-def] - return classmethod(self.fget).__get__(None, owner)() - - class Collection(object): def add(self, e): @@ -1275,6 +1270,29 @@ class Locale(Object): language = None # type: str variant = None # type: Optional[str] + # Class attribute constants + CANADA = None # type: Locale + CANADA_FRENCH = None # type: Locale + CHINA = None # type: Locale + CHINESE = None # type: Locale + ENGLISH = None # type: Locale + FRANCE = None # type: Locale + FRENCH = None # type: Locale + GERMAN = None # type: Locale + GERMANY = None # type: Locale + ITALIAN = None # type: Locale + ITALY = None # type: Locale + JAPAN = None # type: Locale + JAPANESE = None # type: Locale + KOREA = None # type: Locale + KOREAN = None # type: Locale + PRC = None # type: Locale + SIMPLIFIED_CHINESE = None # type: Locale + TAIWAN = None # type: Locale + TRADITIONAL_CHINESE = None # type: Locale + UK = None # type: Locale + US = None # type: Locale + def __init__(self, language, country=None, variant=None): # type: (str, Optional[str], Optional[str]) -> None super(Locale, self).__init__() @@ -1282,111 +1300,6 @@ def __init__(self, language, country=None, variant=None): self.country = country self.variant = variant - @classproperty - def CANADA(self): - # type: () -> Locale - return Locale("en", "CA") - - @classproperty - def CANADA_FRENCH(self): - # type: () -> Locale - return Locale("fr", "CA") - - @classproperty - def CHINA(self): - # type: () -> Locale - return Locale("zh", "CN") - - @classproperty - def CHINESE(self): - # type: () -> Locale - return Locale("zh") - - @classproperty - def ENGLISH(self): - # type: () -> Locale - return Locale("en") - - @classproperty - def FRANCE(self): - # type: () -> Locale - return Locale("fr", "FR") - - @classproperty - def FRENCH(self): - # type: () -> Locale - return Locale("fr") - - @classproperty - def GERMAN(self): - # type: () -> Locale - return Locale("de") - - @classproperty - def GERMANY(self): - # type: () -> Locale - return Locale("de", "DE") - - @classproperty - def ITALIAN(self): - # type: () -> Locale - return Locale("it") - - @classproperty - def ITALY(self): - # type: () -> Locale - return Locale("it", "IT") - - @classproperty - def JAPAN(self): - # type: () -> Locale - return Locale("ja", "JP") - - @classproperty - def JAPANESE(self): - # type: () -> Locale - return Locale("ja") - - @classproperty - def KOREA(self): - # type: () -> Locale - return Locale("ko", "KR") - - @classproperty - def KOREAN(self): - # type: () -> Locale - return Locale("ko") - - @classproperty - def PRC(self): - # type: () -> Locale - return Locale("zh", "CN") - - @classproperty - def SIMPLIFIED_CHINESE(self): - # type: () -> Locale - return Locale("zh", "CN") - - @classproperty - def TAIWAN(self): - # type: () -> Locale - return Locale("zh", "TW") - - @classproperty - def TRADITIONAL_CHINESE(self): - # type: () -> Locale - return Locale("zh", "TW") - - @classproperty - def UK(self): - # type: () -> Locale - return Locale("en", "GB") - - @classproperty - def US(self): - # type: () -> Locale - return Locale("en", "US") - def __str__(self): # type: () -> str ret = self.language @@ -1401,6 +1314,29 @@ def __repr__(self): return "{!r}".format(self.__str__()) +Locale.CANADA = Locale("en", "CA") +Locale.CANADA_FRENCH = Locale("fr", "CA") +Locale.CHINA = Locale("zh", "CN") +Locale.CHINESE = Locale("zh") +Locale.ENGLISH = Locale("en") +Locale.FRANCE = Locale("fr", "FR") +Locale.FRENCH = Locale("fr") +Locale.GERMAN = Locale("de") +Locale.GERMANY = Locale("de", "DE") +Locale.ITALIAN = Locale("it") +Locale.ITALY = Locale("it", "IT") +Locale.JAPAN = Locale("ja", "JP") +Locale.JAPANESE = Locale("ja") +Locale.KOREA = Locale("ko", "KR") +Locale.KOREAN = Locale("ko") +Locale.PRC = Locale("zh", "CN") +Locale.SIMPLIFIED_CHINESE = Locale("zh", "CN") +Locale.TAIWAN = Locale("zh", "TW") +Locale.TRADITIONAL_CHINESE = Locale("zh", "TW") +Locale.UK = Locale("en", "GB") +Locale.US = Locale("en", "US") + + class Properties(Hashtable): def __init__(self, *args): # type: (*Any) -> None