How to use the bidict.IGNORE function in bidict

To help you get started, we’ve selected a few bidict 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 jab / bidict / tests / properties / _strategies.py View on Github external
from bidict.compat import PY2

from . import _types as t


# pylint: disable=invalid-name

BIDICT_TYPES = st.sampled_from(t.BIDICT_TYPES)
MUTABLE_BIDICT_TYPES = st.sampled_from(t.MUTABLE_BIDICT_TYPES)
FROZEN_BIDICT_TYPES = st.sampled_from(t.FROZEN_BIDICT_TYPES)
ORDERED_BIDICT_TYPES = st.sampled_from(t.ORDERED_BIDICT_TYPES)
MAPPING_TYPES = st.sampled_from(t.MAPPING_TYPES)
NON_BIDICT_MAPPING_TYPES = st.sampled_from(t.NON_BIDICT_MAPPING_TYPES)
ORDERED_MAPPING_TYPES = st.sampled_from(t.ORDERED_MAPPING_TYPES)
HASHABLE_MAPPING_TYPES = st.sampled_from(t.HASHABLE_MAPPING_TYPES)
DUP_POLICIES = st.sampled_from((IGNORE, OVERWRITE, RAISE))
DUP_POLICIES_DICT = st.fixed_dictionaries(dict(
    on_dup_key=DUP_POLICIES,
    on_dup_val=DUP_POLICIES,
    on_dup_kv=DUP_POLICIES,
))

TEXT = st.text()
BOOLEANS = st.booleans()
ATOMS = st.none() | BOOLEANS | st.integers()
## Uncomment the following to mix in floats and text. Leaving commented out since it
## slows example generation without actually finding more falsifying examples.
# ATOMS != st.floats(allow_nan=False) | TEXT
NON_MAPPINGS = ATOMS | st.iterables(ATOMS)
HASHABLES = ATOMS
## Uncomment the following to mix in tuples (of tuples...) of ATOMS. Leaving commented
## out since it slows example generation without finding more falsifying examples.
github jab / bidict / tests / test_hypothesis.py View on Github external
MyNamedFrozenBidict = namedbidict('MyNamedBidict', 'key', 'val', base_type=frozenbidict)
NAMEDBIDICT_VALID_NAME = re.compile('[A-z][A-z0-9_]*$')
MUTABLE_BIDICT_TYPES = (
    bidict, OrderedBidict, MyNamedBidict)
IMMUTABLE_BIDICT_TYPES = (frozenbidict, FrozenOrderedBidict, MyNamedFrozenBidict)
ORDERED_BIDICT_TYPES = (OrderedBidict, FrozenOrderedBidict)
BIDICT_TYPES = MUTABLE_BIDICT_TYPES + IMMUTABLE_BIDICT_TYPES
MAPPING_TYPES = BIDICT_TYPES + (dict, OrderedDict)
H_BIDICT_TYPES = strat.sampled_from(BIDICT_TYPES)
H_MUTABLE_BIDICT_TYPES = strat.sampled_from(MUTABLE_BIDICT_TYPES)
H_IMMUTABLE_BIDICT_TYPES = strat.sampled_from(IMMUTABLE_BIDICT_TYPES)
H_ORDERED_BIDICT_TYPES = strat.sampled_from(ORDERED_BIDICT_TYPES)
H_MAPPING_TYPES = strat.sampled_from(MAPPING_TYPES)
H_NAMES = strat.sampled_from(('valid1', 'valid2', 'valid3', 'in-valid'))

H_DUP_POLICIES = strat.sampled_from((IGNORE, OVERWRITE, RAISE))
H_BOOLEANS = strat.booleans()
H_TEXT = strat.text()
H_NONE = strat.none()
H_IMMUTABLES = H_BOOLEANS | H_TEXT | H_NONE | strat.integers() | strat.floats(allow_nan=False)
H_NON_MAPPINGS = H_NONE
H_PAIRS = strat.tuples(H_IMMUTABLES, H_IMMUTABLES)
H_LISTS_PAIRS = strat.lists(H_PAIRS)
H_LISTS_PAIRS_NODUP = H_LISTS_PAIRS.map(prune_dup)
H_LISTS_PAIRS_DUP = (
    H_LISTS_PAIRS.map(ensure_dup(key=True)) |
    H_LISTS_PAIRS.map(ensure_dup(val=True)) |
    H_LISTS_PAIRS.map(ensure_dup(key=True, val=True)))
H_TEXT_PAIRS = strat.tuples(H_TEXT, H_TEXT)
H_LISTS_TEXT_PAIRS_NODUP = strat.lists(H_TEXT_PAIRS).map(prune_dup)
H_METHOD_ARGS = strat.sampled_from((
    # 0-arity
github supposedly / nutshell / nutshell / segment_types / table / table.py View on Github external
from ._transformer import Preprocess
from ._classes import VarName, StateList
from . import _symutils as symutils, _neighborhoods as nbhoods

# no need to catch \s*,\s* because directive values are translated with KILL_WS
CUSTOM_NBHD = re.compile(r'(?:[NS][EW]?|[EW])(?:,(?:[NS][EW]?|[EW]))*')


def generate_cardinals(d):
    """{'name': ('N', 'E', ...)} >>> {'name': {'N' :: 1, 'E' :: 2, ...}}"""
    return {k: bidict.bidict(enumerate(v, 1)).inv for k, v in d.items()}


class Bidict(bidict.bidict):
    on_dup_kv = bidict.IGNORE
    on_dup_val = bidict.IGNORE


class TableSegment:
    CARDINALS = generate_cardinals({
      'oneDimensional': ('W', 'E'),
      'vonNeumann': ('N', 'E', 'S', 'W'),
      'hexagonal': ('N', 'E', 'SE', 'S', 'W', 'NW'),
      'Moore': ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'),
      })
    TRLENS = {k: len(v) for k, v in CARDINALS.items()}

    def __init__(self, tbl, start=0, *, dep: ['@NUTSHELL'] = (None,)):
        # parser (lexer?) dies if there are blank lines right at the start
        # so idk
        tbl = list(tbl)
        while tbl and not tbl[0].split('#', 1)[0].strip():
github supposedly / nutshell / nutshell / segment_types / table / table.py View on Github external
from .lark_assets import parser as lark_standalone
from ._transformer import Preprocess
from ._classes import VarName, StateList
from . import _symutils as symutils, _neighborhoods as nbhoods

# no need to catch \s*,\s* because directive values are translated with KILL_WS
CUSTOM_NBHD = re.compile(r'(?:[NS][EW]?|[EW])(?:,(?:[NS][EW]?|[EW]))*')


def generate_cardinals(d):
    """{'name': ('N', 'E', ...)} >>> {'name': {'N' :: 1, 'E' :: 2, ...}}"""
    return {k: bidict.bidict(enumerate(v, 1)).inv for k, v in d.items()}


class Bidict(bidict.bidict):
    on_dup_kv = bidict.IGNORE
    on_dup_val = bidict.IGNORE


class TableSegment:
    CARDINALS = generate_cardinals({
      'oneDimensional': ('W', 'E'),
      'vonNeumann': ('N', 'E', 'S', 'W'),
      'hexagonal': ('N', 'E', 'SE', 'S', 'W', 'NW'),
      'Moore': ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'),
      })
    TRLENS = {k: len(v) for k, v in CARDINALS.items()}

    def __init__(self, tbl, start=0, *, dep: ['@NUTSHELL'] = (None,)):
        # parser (lexer?) dies if there are blank lines right at the start
        # so idk
        tbl = list(tbl)