import os
from typing import Optional, List

from jobs.base.job import Job

# If on a K8s cluster then use the K8s-based sessions
# otherwise use the subsprocess-based session
if "KUBERNETES_SERVICE_HOST" in os.environ:
    from .kubernetes_session import KubernetesSession

    Session = KubernetesSession  # type: ignore
else:
    from .subprocess_session import SubprocessSession

    Session = SubprocessSession  # type: ignore

Session.name = "session"

from typing import Type, Union

from .kubernetes_session import api_instance, KubernetesSession
from .subprocess_session import SubprocessSession

# If on a K8s is available then use that
# otherwise use the subsprocess-based session
Session: Type[Union[KubernetesSession, SubprocessSession]]
if api_instance is not None:
    Session = KubernetesSession
else:
    Session = SubprocessSession

Session.name = "session"

Improve switching between session types
fix(Worker): Improve switching between session types

+ from typing import Type, Union
- import os
- from typing import Optional, List
  
- from jobs.base.job import Job
+ from .kubernetes_session import api_instance, KubernetesSession
+ from .subprocess_session import SubprocessSession
  
- # If on a K8s cluster then use the K8s-based sessions
+ # If on a K8s is available then use that
  # otherwise use the subsprocess-based session
+ Session: Type[Union[KubernetesSession, SubprocessSession]]
+ if api_instance is not None:
- if "KUBERNETES_SERVICE_HOST" in os.environ:
-     from .kubernetes_session import KubernetesSession
- 
-     Session = KubernetesSession  # type: ignore
+     Session = KubernetesSession
  else:
-     from .subprocess_session import SubprocessSession
- 
-     Session = SubprocessSession  # type: ignore
+     Session = SubprocessSession
  
  Session.name = "session"
  
Improve switching between session types
## Code Before:
import os
from typing import Optional, List

from jobs.base.job import Job

# If on a K8s cluster then use the K8s-based sessions
# otherwise use the subsprocess-based session
if "KUBERNETES_SERVICE_HOST" in os.environ:
    from .kubernetes_session import KubernetesSession

    Session = KubernetesSession  # type: ignore
else:
    from .subprocess_session import SubprocessSession

    Session = SubprocessSession  # type: ignore

Session.name = "session"

## Instruction:
Improve switching between session types
## Code After:
from typing import Type, Union

from .kubernetes_session import api_instance, KubernetesSession
from .subprocess_session import SubprocessSession

# If on a K8s is available then use that
# otherwise use the subsprocess-based session
Session: Type[Union[KubernetesSession, SubprocessSession]]
if api_instance is not None:
    Session = KubernetesSession
else:
    Session = SubprocessSession

Session.name = "session"
