Skip to content

Commit

Permalink
Fix backwards compatibility for union (#214)
Browse files Browse the repository at this point in the history
In python 3.9 and below you can't do something like str | None in the
type definition of a function's arguments. However, this can be fixed by
using __future__.

Python stores the annotations as strings and doesn't try to evaluate
them. This allows you to write type hints using Python 3.10's syntax in
a Python 3.9 environment. When the code is actually run, the annotations
aren't evaluated, so there's no issue with the interpreter not
understanding the | operator for union types.

I checked and the | is only in this one file, elsewhere we are using Union. I replaced the | with Unions to make it consistent.
ValentaTomas authored Nov 9, 2023
2 parents cbc9f45 + 521495d commit 9388a4e
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-lemons-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@e2b/python-sdk": patch
---

Fix Python 3.8 compatibility
6 changes: 4 additions & 2 deletions packages/python-sdk/e2b/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from importlib.metadata import version
from typing import Union

from e2b.constants import API_HOST
from e2b.api.metadata import default_headers


pydantic_version = version("pydantic")
if pydantic_version < "2.0.0":
import e2b.api.v1.client as client
@@ -24,8 +26,8 @@
class E2BApiClient(client.ApiClient):
def __init__(
self,
api_key: str | None = None,
access_token: str | None = None,
api_key: Union[str, None] = None,
access_token: Union[str, None] = None,
*args,
**kwargs,
):

0 comments on commit 9388a4e

Please sign in to comment.