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

DM-36108: move Ellipsis typing workaround to utils #730

Merged
merged 2 commits into from
Sep 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/DM-36108.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Moved the typing workaround for the built-in `Ellipsis` (`...`) singleton to `utils`.
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import traceback
from contextlib import contextmanager
from logging import Formatter, LogRecord, StreamHandler
from typing import IO, Any, ClassVar, Dict, Generator, Iterable, Iterator, List, Optional, Union
from typing import IO, Any, Callable, ClassVar, Dict, Generator, Iterable, Iterator, List, Optional, Union

from lsst.utils.introspection import get_full_type_name
from lsst.utils.iteration import isplit
Expand Down Expand Up @@ -71,7 +71,7 @@ class ButlerMDC:

_MDC = MDCDict()

_old_factory = None
_old_factory: Optional[Callable[..., logging.LogRecord]] = None
"""Old log record factory."""

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
_V = TypeVar("_V", bound=Collection)


class ProgressBar(Protocol, Iterable[_T]):
class ProgressBar(Iterable[_T], Protocol):
"""A structural interface for progress bars that wrap iterables.

An object conforming to this interface can be obtained from the
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from lsst.utils.iteration import ensure_iterable

if TYPE_CHECKING:
from ..registry.wildcards import Ellipsis, EllipsisType
from lsst.utils.ellipsis import Ellipsis, EllipsisType


_LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/registry/dimensions/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from typing import AbstractSet, Any, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Set, Union

import sqlalchemy
from lsst.utils.ellipsis import Ellipsis, EllipsisType

from ...core import (
DatabaseDimensionElement,
Expand Down Expand Up @@ -56,7 +57,6 @@
StaticTablesContext,
)
from ..queries import QueryBuilder
from ..wildcards import Ellipsis, EllipsisType

_LOG = logging.getLogger(__name__)

Expand Down
22 changes: 1 addition & 21 deletions python/lsst/daf/butler/registry/wildcards.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
)

import sqlalchemy
from lsst.utils.ellipsis import Ellipsis, EllipsisType
from lsst.utils.iteration import ensure_iterable
from pydantic import BaseModel

Expand All @@ -51,29 +52,8 @@
from ._collectionType import CollectionType

if TYPE_CHECKING:
# Workaround for `...` not having an exposed type in Python, borrowed from
# https://github.com/python/typing/issues/684#issuecomment-548203158
# Along with that, we need to either use `Ellipsis` instead of `...` for
# the actual sentinal value internally, and tell MyPy to ignore conversions
# from `...` to `Ellipsis` at the public-interface boundary.
#
# `Ellipsis` and `EllipsisType` should be directly imported from this
# module by related code that needs them; hopefully that will stay confined
# to `lsst.daf.butler.registry`. Putting these in __all__ is bad for
# Sphinx, and probably more confusing than helpful overall.
from enum import Enum

from .interfaces import CollectionManager, CollectionRecord

class EllipsisType(Enum):
Ellipsis = "..."

Ellipsis = EllipsisType.Ellipsis

else:
EllipsisType = type(Ellipsis)
Ellipsis = Ellipsis


@dataclass
class CategorizedWildcard:
Expand Down