Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions jupyter_core/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Iterator, Optional
from typing import Any, Iterator, Literal, Optional, overload

import platformdirs

Expand All @@ -38,6 +38,14 @@
UF_HIDDEN = getattr(stat, "UF_HIDDEN", 32768)


@overload
def envset(name: str, default: bool = False) -> bool: ...


@overload
def envset(name: str, default: Literal[None]) -> Optional[bool]: ...


def envset(name: str, default: Optional[bool] = False) -> Optional[bool]:
"""Return the boolean value of a given environment variable.

Expand All @@ -58,7 +66,7 @@ def use_platform_dirs() -> bool:
We plan for this to default to False in jupyter_core version 5 and to True
in jupyter_core version 6.
"""
return envset("JUPYTER_PLATFORM_DIRS", False) # type:ignore[return-value]
return envset("JUPYTER_PLATFORM_DIRS", False)


def get_home_dir() -> str:
Expand Down Expand Up @@ -103,7 +111,7 @@ def prefer_environment_over_user() -> bool:
"""Determine if environment-level paths should take precedence over user-level paths."""
# If JUPYTER_PREFER_ENV_PATH is defined, that signals user intent, so return its value
if "JUPYTER_PREFER_ENV_PATH" in os.environ:
return envset("JUPYTER_PREFER_ENV_PATH") # type:ignore[return-value]
return envset("JUPYTER_PREFER_ENV_PATH")

# If we are in a Python virtualenv, default to True (see https://docs.python.org/3/library/venv.html#venv-def)
if sys.prefix != sys.base_prefix and _do_i_own(sys.prefix):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ ignore-semiprivate=true
ignore-property-decorators=true
ignore-nested-functions=true
ignore-nested-classes=true
ignore-overloaded-functions=true
fail-under=100
exclude = ["docs", "tests"]

Expand Down
Loading