Skip to content

ApiError (via core) not properly exposed in __init__.py leading to poor developer experience #804

@StephenWithPH

Description

@StephenWithPH

Checklist

  • I have looked into the Readme and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I believe this is loosely similar to #793 . In this case, it seems ApiError is not properly referenced because core is not properly referenced:

core/init.py actually has ApiError in both the TYPE_CHECKING block and
all. So from auth0.management.core import ApiError should be resolvable by PyCharm. The
problem is one level up — PyCharm can't resolve auth0.management.core as a subpackage because
auth0.management.init.py doesn't reference core.

Image

This happens to make the README somewhat troubling...

auth0-python/README.md

Lines 182 to 195 in e506d73

## Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.
```python
from auth0.management.core.api_error import ApiError
try:
client.actions.create(...)
except ApiError as e:
print(e.status_code)
print(e.body)
```

... in that using the following code produces what seems like an error:

Reproduction

# noinspection PyProtectedMember
from auth0.management import ManagementClient  # type: ignore[attr-defined]  # https://github.com/auth0/auth0-python/pull/785#issuecomment-4137213608
from auth0.management.core.api_error import ApiError # <---- you will see the intellisense error here

client = ManagementClient(
    domain="YOUR_TENANT.auth0.com",
    token="YOUR_TOKEN",
)

try:
    client.actions.create(...)
except ApiError as e:
    print(e.status_code)
    print(e.body)

Additional context

No response

auth0-python version

5.1.0

Python version

Python 3.13.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis points to a verified bug in the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions