How to use typing - 10 common examples

To help you get started, we’ve selected a few typing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mirantis / disk_perf_test_tool / wally / hw_info.py View on Github external
for slot_node in mem_node.find("node[@class='memory']"):
                        slot_sz = slot_node.find('size')
                        if slot_sz is not None:
                            assert slot_sz.attrib['units'] == 'bytes'
                            res.ram_size += int(slot_sz.text)
                else:
                    assert mem_sz.attrib['units'] == 'bytes'
                    res.ram_size += int(mem_sz.text)
        except Exception:
            pass

    for net in core.findall(".//node[@class='network']"):
        try:
            link = net.find("configuration/setting[@id='link']")
            if link.attrib['value'] == 'yes':
                name = cast(str, net.find("logicalname").text)
                speed_node = net.find("configuration/setting[@id='speed']")

                if speed_node is None:
                    speed = None
                else:
                    speed = int(speed_node.attrib['value'])

                dup_node = net.find("configuration/setting[@id='duplex']")
                if dup_node is None:
                    dup = None
                else:
                    dup = cast(str, dup_node.attrib['value']).lower() == 'yes'

                ips = []  # type: List[str]
                res.net_info[name] = (speed, dup, ips)
        except Exception:
github databand-ai / dbnd / modules / dbnd / test_dbnd / task / task_data / test_task_output.py View on Github external
def test_multiple_outputs_inline(self):
        def _partitions(task, to):
            root = to.build_target(task)
            return {t: root.partition(name="t_output/%s" % t) for t in task.t_types}

        class TTaskMultipleOutputs(TTask):
            t_types = parameter(default=[1, 2])[List]
            t_output = output.folder(output_factory=_partitions)

            def run(self):
                for t_name, t_target in six.iteritems(self.t_output):
                    t_target.write("%s" % t_name)

        task = TTaskMultipleOutputs()
        assert_run_task(task)
        logger.error(task.t_output)
github python / typing / python2 / test_typing.py View on Github external
def test_optional(self):
        EmpD = TypedDict(b'EmpD', name=str, id=int)

        self.assertEqual(typing.Optional[EmpD], typing.Union[None, EmpD])
        self.assertNotEqual(typing.List[EmpD], typing.Tuple[EmpD])
github tribe29 / checkmk / tests / unit / cmk / gui / test_userdb_ldap_connector.py View on Github external
"cn": ["Härry Hörsch"],
            "samaccountname": ["härry"],
            "userPassword": ["ldap-test"],
            "mail": ["härry@check-mk.org"],
        },
        "cn=sync-user,ou=users,dc=check-mk,dc=org": {
            "objectclass": ["user"],
            "objectcategory": ["person"],
            "dn": ["cn=sync-user,ou=users,dc=check-mk,dc=org"],
            "cn": ["sync-user"],
            "samaccountname": ["sync-user"],
            "userPassword": ["sync-secret"],
        },
    }

    groups: Dict[str, Dict[str, Union[str, List[str]]]] = {
        "cn=admins,ou=groups,dc=check-mk,dc=org": {
            "objectclass": ["group"],
            "objectcategory": ["group"],
            "dn": ["cn=admins,ou=groups,dc=check-mk,dc=org"],
            "cn": ["admins"],
            "member": ["cn=admin,ou=users,dc=check-mk,dc=org",],
        },
        u"cn=älle,ou=groups,dc=check-mk,dc=org": {
            "objectclass": ["group"],
            "objectcategory": ["group"],
            "dn": [u"cn=älle,ou=groups,dc=check-mk,dc=org"],
            "cn": ["alle"],
            "member": [
                "cn=admin,ou=users,dc=check-mk,dc=org",
                "cn=härry,ou=users,dc=check-mk,dc=org",
            ],
github nuxeo / nuxeo-drive / tests / unit / test_autolock.py View on Github external
"""
from pathlib import Path
from typing import Dict, List, Tuple
from unittest.mock import Mock, patch

import pytest
import nxdrive.autolocker

from .. import ensure_no_exception


class DAO:
    """Minimal ManagerDAO for a working Auto-Lock."""

    # {path: (process, doc_id)}
    paths: Dict[str, Tuple[int, str]] = {}

    def get_locked_paths(self) -> List[str]:
        return list(self.paths.keys())

    def lock_path(self, path: str, process: int, doc_id: str) -> None:
        self.paths[path] = (process, doc_id)

    def unlock_path(self, path: str) -> None:
        self.paths.pop(path, None)


@pytest.fixture(scope="function")
def autolock(tmpdir):
    check_interval = 5
    autolocker = nxdrive.autolocker.ProcessAutoLockerWorker(
        check_interval, DAO(), Path(tmpdir)
github python / typing / src / test_typing.py View on Github external
def test_cannot_instantiate_vars(self):
        with self.assertRaises(TypeError):
            TypeVar('A')()
github python / mypy / lib-typing / 3.2 / test_typing.py View on Github external
def test_cannot_instantiate(self):
        with self.assertRaises(TypeError):
            Union()
        with self.assertRaises(TypeError):
            type(Union)()
        u = Union[int, float]
        with self.assertRaises(TypeError):
            u()
        with self.assertRaises(TypeError):
            type(u)()
github python / typing / src / test_typing.py View on Github external
def test_namedtuple_errors(self):
        with self.assertRaises(TypeError):
            NamedTuple.__new__()
        with self.assertRaises(TypeError):
            NamedTuple()
        with self.assertRaises(TypeError):
            NamedTuple('Emp', [('name', str)], None)
        with self.assertRaises(ValueError):
            NamedTuple('Emp', [('_name', str)])

        with self.assertWarns(DeprecationWarning):
            Emp = NamedTuple(typename='Emp', name=str, id=int)
        self.assertEqual(Emp.__name__, 'Emp')
        self.assertEqual(Emp._fields, ('name', 'id'))

        with self.assertWarns(DeprecationWarning):
            Emp = NamedTuple('Emp', fields=[('name', str), ('id', int)])
        self.assertEqual(Emp.__name__, 'Emp')
        self.assertEqual(Emp._fields, ('name', 'id'))