Skip to content

Conversation

@cesarcoatl
Copy link
Member

@cesarcoatl cesarcoatl commented Dec 6, 2025

drop classproperty decorator

Summary by Sourcery

Replace dynamic Locale classproperty-based constants with static class attributes initialized after class definition.

Enhancements:

  • Remove custom classproperty helper and use explicit class attributes for Locale constants to better reflect Java-style static constants in Python API.
  • Update type stubs to declare Locale constants as class attributes instead of methods.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 6, 2025

Reviewer's Guide

Refactors java.util.Locale to replace a custom classproperty-based pattern with concrete class-level constants and updates type stubs accordingly, simplifying attribute access and removing the bespoke descriptor.

Class diagram for refactored java.util.Locale constants

classDiagram
    class Object

    class Locale {
        +str country
        +str language
        +Optional_str variant
        +Locale 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
        +__init__(language, country, variant)
        +__str__()
        +__repr__()
    }

    class classproperty {
        -__get__(cls, owner)
    }

    Locale --|> Object
    %% classproperty is removed in this refactor and no longer used by Locale
Loading

File-Level Changes

Change Details Files
Replace classproperty-based Locale factory methods with initialized class attributes to represent standard Locale constants.
  • Remove custom classproperty descriptor implementation from the runtime module.
  • Add typed class attributes for each standard Locale constant on the Locale class definition, initialized to None for type checking.
  • Instantiate each Locale constant once at module load time and assign it to the corresponding Locale class attribute, preserving existing values for each constant.
java-api/src/java/util/__init__.py
Align type stubs with new Locale constant attribute pattern instead of methods.
  • Remove classproperty descriptor declaration from the stubs module.
  • Declare each standard Locale constant (e.g., CANADA, US, FRANCE) as a class attribute of type Locale on the Locale stub.
  • Delete stub method signatures for the old constant-style methods (e.g., def CANADA(self) -> Locale).
java-api-stubs/stubs/java/util/__init__.pyi

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Switching from @classproperty methods that returned new Locale instances on each access to shared class attributes changes semantics around mutability; if callers mutate these constants (e.g., Locale.CANADA.language = ...), it will now be global state instead of per-access copies, so consider either making Locale effectively immutable or returning defensive copies from accessors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Switching from `@classproperty` methods that returned new `Locale` instances on each access to shared class attributes changes semantics around mutability; if callers mutate these constants (e.g., `Locale.CANADA.language = ...`), it will now be global state instead of per-access copies, so consider either making `Locale` effectively immutable or returning defensive copies from accessors.

## Individual Comments

### Comment 1
<location> `java-api-stubs/stubs/java/util/__init__.pyi:459-468` </location>
<code_context>
     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] = ...
</code_context>

<issue_to_address>
**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.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +459 to +468
CANADA: Locale
CANADA_FRENCH: Locale
CHINA: Locale
CHINESE: Locale
ENGLISH: Locale
FRANCE: Locale
FRENCH: Locale
GERMAN: Locale
GERMANY: Locale
ITALIAN: Locale
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.

@cesarcoatl cesarcoatl merged commit 0c1badb into 17 Dec 6, 2025
5 checks passed
@cesarcoatl cesarcoatl deleted the refactor/java/util-Locale-constants branch December 6, 2025 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants