Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import from typing_extensions instead of typing #365

Merged
merged 7 commits into from
Dec 20, 2024
2 changes: 1 addition & 1 deletion examples/connect/databricks/fastapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING, Annotated

from databricks import sql
from databricks.sdk.core import Config, databricks_cli
from fastapi import FastAPI, Header
from typing_extensions import TYPE_CHECKING, Annotated

from posit.connect.external.databricks import PositCredentialsStrategy

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest
from typing_extensions import TYPE_CHECKING

from posit import connect

Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any
from typing_extensions import Any


def update_dict_values(obj: dict[str, Any], /, **kwargs: Any) -> None:
Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from __future__ import annotations

import io
from typing import TYPE_CHECKING, List

from typing_extensions import TYPE_CHECKING, List

from . import resources, tasks

Expand Down
3 changes: 1 addition & 2 deletions src/posit/connect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, overload

from requests import Response, Session
from typing_extensions import TYPE_CHECKING, overload

from . import hooks, me
from .auth import Auth
Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Client configuration."""

import os
from typing import Optional

from typing_extensions import Optional

from . import urls

Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import functools
import weakref
from typing import TYPE_CHECKING, Protocol

from packaging.version import Version
from typing_extensions import TYPE_CHECKING, Protocol

if TYPE_CHECKING:
from .client import Client
Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/cursors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Generator, List

from typing_extensions import TYPE_CHECKING, Any, Generator, List

if TYPE_CHECKING:
from .context import Context
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Iterator, List, Mapping, MutableMapping, Optional
from typing_extensions import TYPE_CHECKING, Any, Iterator, List, Mapping, MutableMapping, Optional

from .resources import Resources

Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from __future__ import annotations

from abc import abstractmethod
from typing import Protocol

from typing_extensions import (
List,
Literal,
Protocol,
TypedDict,
runtime_checkable,
)
Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Any

from typing_extensions import Any


class ClientError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/external/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"""

import abc
from typing import Callable, Dict, Optional

import requests
from typing_extensions import Callable, Dict, Optional

from ..client import Client
from ..oauth import Credentials
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/external/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
The APIs in this module are provided as a convenience and are subject to breaking changes.
"""

from typing import Optional
from typing_extensions import Optional

from ..client import Client
from .external import is_local
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, List, Optional, overload
from typing_extensions import TYPE_CHECKING, List, Optional, overload

from .paginator import Paginator
from .resources import BaseResource, Resources
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import (
from typing_extensions import (
Iterable,
Literal,
Protocol,
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/metrics/shiny_usage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, overload
from typing_extensions import List, overload

from ..cursors import CursorPaginator
from ..resources import BaseResource, Resources
Expand Down
3 changes: 1 addition & 2 deletions src/posit/connect/metrics/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from __future__ import annotations

from typing import List, overload

from requests.sessions import Session as Session
from typing_extensions import List, overload

from .. import resources
from . import shiny_usage, visits
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/metrics/visits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, overload
from typing_extensions import List, overload

from ..cursors import CursorPaginator
from ..resources import BaseResource, Resources
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/oauth/associations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""OAuth association resources."""

from typing import List
from typing_extensions import List

from ..context import Context
from ..resources import BaseResource, Resources
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/oauth/integrations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""OAuth integration resources."""

from typing import List, Optional, overload
from typing_extensions import List, Optional, overload

from ..resources import BaseResource, Resources
from .associations import IntegrationAssociations
Expand Down
3 changes: 1 addition & 2 deletions src/posit/connect/oauth/oauth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING, Optional

from typing_extensions import TypedDict
from typing_extensions import TYPE_CHECKING, Optional, TypedDict

from ..resources import Resources
from .integrations import Integrations
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/oauth/sessions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""OAuth session resources."""

from typing import List, Optional, overload
from typing_extensions import List, Optional, overload

from ..resources import BaseResource, Resources

Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/paginator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, Generator, List

from typing_extensions import TYPE_CHECKING, Generator, List

if TYPE_CHECKING:
from .context import Context
Expand Down
3 changes: 1 addition & 2 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, List, Optional, overload

from requests.sessions import Session as Session
from typing_extensions import TYPE_CHECKING, List, Optional, overload

from .resources import BaseResource, Resources

Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import posixpath
import warnings
from abc import ABC
from typing import (

from typing_extensions import (
TYPE_CHECKING,
Any,
Hashable,
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, List, Literal, overload

from typing_extensions import TypedDict, Unpack
from typing_extensions import TYPE_CHECKING, List, Literal, TypedDict, Unpack, overload

from .context import ContextManager
from .resources import Active
Expand Down
3 changes: 1 addition & 2 deletions src/posit/connect/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional, overload

from typing_extensions import NotRequired, TypedDict, Unpack
from typing_extensions import TYPE_CHECKING, NotRequired, Optional, TypedDict, Unpack, overload

from ._utils import update_dict_values
from .context import Context, ContextManager
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import overload
from typing_extensions import overload

from . import resources

Expand Down
12 changes: 9 additions & 3 deletions src/posit/connect/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

from __future__ import annotations

from typing import TYPE_CHECKING, List, Literal

from typing_extensions import NotRequired, Required, TypedDict, Unpack
from typing_extensions import (
TYPE_CHECKING,
List,
Literal,
NotRequired,
Required,
TypedDict,
Unpack,
)

from . import me
from .content import Content
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/vanities.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Vanity URL resources."""

from typing import Callable, List, Optional

from typing_extensions import NotRequired, Required, TypedDict, Unpack
from typing_extensions import Callable, List, NotRequired, Optional, Required, TypedDict, Unpack

from .context import Context
from .errors import ClientError
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/variants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing_extensions import List

from .context import Context
from .resources import BaseResource, Resources
Expand Down
2 changes: 1 addition & 1 deletion tests/posit/connect/external/test_databricks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import base64
from typing import Dict
from unittest.mock import patch

import pytest
import responses
from typing_extensions import Dict

from posit.connect import Client
from posit.connect.external.databricks import (
Expand Down
20 changes: 20 additions & 0 deletions tests/posit/connect/test_internal_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

import pytest

here = Path(__file__).resolve().parent
root_dir = here.parent.parent.parent

tests_dir = root_dir / "tests"
src_dir = root_dir / "src"
integration_tests_dir = tests_dir / "integration" / "tests"


@pytest.mark.parametrize("path", [tests_dir, src_dir, integration_tests_dir])
def test_no_from_typing_imports(path: Path):
for python_file in path.rglob("*.py"):
file_txt = python_file.read_text()
if "\nfrom typing import" in file_txt:
raise ValueError(
f"Found `from typing import` in {python_file.relative_to(root_dir)}. Please replace the import with `typing_extensions`."
)
3 changes: 1 addition & 2 deletions tests/posit/connect/test_jobs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import TYPE_CHECKING

import pytest
import responses
from requests.exceptions import HTTPError
from typing_extensions import TYPE_CHECKING

from posit.connect.client import Client

Expand Down
3 changes: 2 additions & 1 deletion tests/posit/connect/test_resources.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import warnings
from typing import Optional
from unittest import mock
from unittest.mock import Mock

from typing_extensions import Optional

from posit.connect.resources import BaseResource

config = Mock()
Expand Down
Loading