Skip to content

Commit

Permalink
Move ellipsis typing workaround to lsst.utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Sep 6, 2022
1 parent cec2a0e commit e8daa3a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 23 deletions.
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`.
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

0 comments on commit e8daa3a

Please sign in to comment.