Skip to content

Commit

Permalink
Merge pull request #53 from lsst/tickets/DM-38492
Browse files Browse the repository at this point in the history
DM-38492: Move ResourcePathExpression definition to end of file
  • Loading branch information
timj committed Apr 12, 2023
2 parents 267b0d9 + a5e7be2 commit aebfb71
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/changes/DM-38492.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* ``ResourcePathExpression`` can now be used in an `isinstance()` call on Python 3.10 and newer.
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ ignore_missing_imports = True
[mypy-botocore.*]
ignore_missing_imports = True

[mypy-moto.*]
ignore_missing_imports = True

[mypy-wsgidav.*]
ignore_missing_imports = True

[mypy-google.*]
ignore_missing_imports = True
ignore_errors = True
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/resources/_resourcePath.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
MAX_WORKERS = 10


ResourcePathExpression = Union[str, urllib.parse.ParseResult, "ResourcePath", Path]
"""Type-annotation alias for objects that can be coerced to ResourcePath.
"""


class ResourcePath:
"""Convenience wrapper around URI parsers.
Expand Down Expand Up @@ -1404,3 +1399,8 @@ def _openImpl(
out_bytes = str_buffer.getvalue().encode(encoding)
if "r" not in mode or "+" in mode:
self.write(out_bytes, overwrite=("x" not in mode))


ResourcePathExpression = Union[str, urllib.parse.ParseResult, ResourcePath, Path]
"""Type-annotation alias for objects that can be coerced to ResourcePath.
"""
2 changes: 1 addition & 1 deletion python/lsst/resources/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def test_ordering(self) -> None:
class GenericReadWriteTestCase(_GenericTestCase):
"""Test schemes that can read and write using concrete resources."""

transfer_modes = ("copy", "move")
transfer_modes: tuple[str, ...] = ("copy", "move")
testdir: Optional[str] = None

def setUp(self) -> None:
Expand Down
23 changes: 22 additions & 1 deletion tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,35 @@

import os
import pathlib
import sys
import unittest
import unittest.mock
import urllib.parse

from lsst.resources import ResourcePath
from lsst.resources import ResourcePath, ResourcePathExpression
from lsst.resources.tests import GenericReadWriteTestCase, GenericTestCase

TESTDIR = os.path.abspath(os.path.dirname(__file__))

_OLD_PYTHON = False
if sys.version_info < (3, 10, 0):
_OLD_PYTHON = True


class SimpleTestCase(unittest.TestCase):
@unittest.skipIf(_OLD_PYTHON, "isinstance() with unions is not supported.")
def test_instance(self):
for example in (
"xxx",
ResourcePath("xxx"),
pathlib.Path("xxx"),
urllib.parse.urlparse("file:///xxx"),
):
self.assertIsInstance(example, ResourcePathExpression)

for example in ({1, 2, 3}, 42, self):
self.assertNotIsInstance(example, ResourcePathExpression)


class FileTestCase(GenericTestCase, unittest.TestCase):
scheme = "file"
Expand Down

0 comments on commit aebfb71

Please sign in to comment.