Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions java-api-stubs/stubs/java/util/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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
Comment on lines +459 to +468
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: These Locale constants in the stub are class-level and probably should be annotated as ClassVar[Locale] rather than instance attributes.

Because these names are declared in the class body, type checkers treat them as instance attributes, even though they’re used as class-level constants (e.g., Locale.CANADA). Annotating them as ClassVar[Locale] (e.g., CANADA: ClassVar[Locale]) will align the stub with actual usage and give static analysis tools the correct class-level semantics.

Suggested implementation:

    CANADA: ClassVar[Locale]
    CANADA_FRENCH: ClassVar[Locale]
    CHINA: ClassVar[Locale]
    CHINESE: ClassVar[Locale]
    ENGLISH: ClassVar[Locale]
    FRANCE: ClassVar[Locale]
    FRENCH: ClassVar[Locale]
    GERMAN: ClassVar[Locale]
    GERMANY: ClassVar[Locale]
    ITALIAN: ClassVar[Locale]
    ITALY: ClassVar[Locale]
    JAPAN: ClassVar[Locale]
    JAPANESE: ClassVar[Locale]
    KOREA: ClassVar[Locale]
    KOREAN: ClassVar[Locale]
    PRC: ClassVar[Locale]
    SIMPLIFIED_CHINESE: ClassVar[Locale]
    TAIWAN: ClassVar[Locale]
    TRADITIONAL_CHINESE: ClassVar[Locale]
    UK: ClassVar[Locale]
    US: ClassVar[Locale]

Ensure ClassVar is imported in this stub file, e.g.:

  • If there is an existing from typing import ... line, add ClassVar to it:
    from typing import Any, Optional, ClassVar (adjust to match the actual list).

  • If there is no typing import yet, add:
    from typing import Any, Optional, ClassVar
    near the top of the file, consistent with existing import style.

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: ...
Expand Down
156 changes: 46 additions & 110 deletions java-api/src/java/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -1275,118 +1270,36 @@ 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__()
self.language = language
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
Expand All @@ -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
Expand Down