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 / 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)
                    assert mem_sz.attrib['units'] == 'bytes'
                    res.ram_size += int(mem_sz.text)
        except Exception:

    for net in core.findall(".//node[@class='network']"):
            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
                    speed = int(speed_node.attrib['value'])

                dup_node = net.find("configuration/setting[@id='duplex']")
                if dup_node is None:
                    dup = None
                    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 / 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()
github python / typing / python2 / 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 / View on Github external
"cn": ["Härry Hörsch"],
            "samaccountname": ["härry"],
            "userPassword": ["ldap-test"],
            "mail": ["hä"],
        "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": [
github nuxeo / nuxeo-drive / tests / unit / 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)

def autolock(tmpdir):
    check_interval = 5
    autolocker = nxdrive.autolocker.ProcessAutoLockerWorker(
        check_interval, DAO(), Path(tmpdir)
github python / typing / src / View on Github external
def test_cannot_instantiate_vars(self):
        with self.assertRaises(TypeError):
github python / mypy / lib-typing / 3.2 / View on Github external
def test_cannot_instantiate(self):
        with self.assertRaises(TypeError):
        with self.assertRaises(TypeError):
        u = Union[int, float]
        with self.assertRaises(TypeError):
        with self.assertRaises(TypeError):
github python / typing / src / View on Github external
def test_namedtuple_errors(self):
        with self.assertRaises(TypeError):
        with self.assertRaises(TypeError):
        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'))