Skip to content

fix(async client): get_default() builds an undefined ApiClient (NameError) - #1098

Open
herniqeu wants to merge 1 commit into
line:masterfrom
herniqeu:fix/async-client-get-default
Open

herniqeu wants to merge 1 commit into
line:masterfrom
herniqeu:fix/async-client-get-default

Conversation

@herniqeu

@herniqeu herniqeu commented Nov 1, 2026

Copy link
Copy Markdown

Problem

In the generated async clients, get_default() points at a class that does not exist in that module:

@classmethod
def get_default(cls):
    if cls._default is None:
        cls._default = ApiClient()      # line 140
    return cls._default

ApiClient is the sync class name; the async module only defines AsyncApiClient. Any call to get_default() (documented as the way to reuse a default client) raises NameError: name 'ApiClient' is not defined.

Fix

cls._default = cls() — the classmethod already gets the right class.

Scope

The same generated pattern exists in the other linebot/v3/*/async_api_client.py modules. I kept this PR to one file so the change is trivial to review; say the word and I extend it to all of them, or point me to the generator template if these files are produced from one.

Verification

python3 -m pyflakes linebot/v3/audience/async_api_client.py — before: undefined name 'ApiClient' (line 140); after: gone.

AsyncApiClient.get_default does cls._default = ApiClient(), but ApiClient is
not imported in the async modules (only AsyncApiClient exists there), so any
call to get_default raises NameError: name 'ApiClient' is not defined. The
classmethod already receives the right class, so cls() is the fix.

The same generated pattern appears in the other v3 async_api_client modules;
I can extend this to all of them in this PR if you prefer.

Verified with pyflakes: undefined name 'ApiClient' no longer reported.

Signed-off-by: Henrique Godoy <95002561+herniqeu@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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