How to use compat_kwargs method in pandera

Best Python code snippet using pandera_python

compat.py

Source:compat.py Github

copy

Full Screen

...149 def _testfunc(x):150 pass151 _testfunc(**{'x': 0})152except TypeError:153 def compat_kwargs(kwargs):154 return dict((bytes(k), v) for k, v in kwargs.items())155else:156 compat_kwargs = lambda kwargs: kwargs157if sys.version_info < (3, 0) and sys.platform == 'win32':158 def compat_getpass(promt, *args, **kwargs):159 if isinstance(promt, compat_str):160 from .utils import preferredencoding161 promt = promt.encode(preferredencoding())162 return getpass.getpass(promt, *args, **kwargs)163else:164 compat_getpass = getpass.getpass165__all__ = [166 'compat_shlex_split', # 分解命令行的参数167 'compat_getenv', # 获取指定key的环境变量...

Full Screen

Full Screen

init_subclass.py

Source:init_subclass.py Github

copy

Full Screen

1"""2Backport of the functionality of `__init_subclass__` from3`PEP 487 <https://peps.python.org/pep-0487/>`_ to Python 2.7.4"""5import sys6import six7from .get_mro import get_mro8__all__ = ["InitSubclassMeta", "InitSubclass"]9class InitSubclassMeta(type):10 """Metaclass that backports the functionality of `__init_subclass__` from PEP 487 to Python 2.7."""11 @staticmethod12 def __new__(mcs, name, bases, dct, **kwargs):13 # Keep a copy of the original kwargs -- they are sometimes used by generics.14 original_kwargs = dict(kwargs)15 # Wipe out kwargs if using older python.16 if sys.version_info[:3] < (3, 6):17 kwargs = dict()18 # Get compatibility kwargs (defined in the body of the class).19 dct_had_kwargs = "__kwargs__" in dct20 if dct_had_kwargs:21 compat_kwargs = dct["__kwargs__"]22 else:23 compat_kwargs = {}24 # Error out if the same kwarg is defined both in the body and in the class arguments.25 conflicting_kwargs = set(compat_kwargs).intersection(kwargs)26 if conflicting_kwargs:27 error = "conflicting class keyword arguments {}".format(28 ", ".join(sorted(repr(k) for k in conflicting_kwargs))29 )30 raise TypeError(error)31 # Merge kwargs.32 kwargs.update(compat_kwargs)33 # For older python versions.34 if sys.version_info[:3] < (3, 6):35 # Ensure classmethod.36 if "__init_subclass__" in dct and not isinstance(dct["__init_subclass__"], classmethod):37 dct = dict(dct)38 dct["__init_subclass__"] = classmethod(dct["__init_subclass__"])39 # Build class and pass original kwargs (for generics).40 cls = super(InitSubclassMeta, mcs).__new__(mcs, name, bases, dct, **original_kwargs)41 # Find '__init_subclass__' method.42 method = None43 method_owner = None44 for base in get_mro(cls):45 if base is cls:46 continue47 method = base.__dict__.get("__init_subclass__")48 if method is not None:49 method_owner = base50 break51 # Found a method.52 if method is not None:53 # Invalid base.54 if not isinstance(method_owner, InitSubclassMeta):55 error = "base {!r} defines '__init_subclass__' but does not utilize {!r} as a metaclass".format(56 method_owner.__name__, InitSubclassMeta.__name__57 )58 raise TypeError(error)59 # Call it with compat kwargs only.60 method.__func__(cls, **compat_kwargs)61 # Have kwargs but no method was found.62 elif kwargs:63 error = "object.__init_subclass__() takes no keyword arguments"64 raise TypeError(error)65 # We don't need to do anything for newer python versions, just pass the merged kwargs.66 else:67 cls = super(InitSubclassMeta, mcs).__new__(mcs, name, bases, dct, **kwargs)68 # Remove kwargs from the body of the class.69 if not dct_had_kwargs and hasattr(cls, "__kwargs__"):70 error = "one or more bases for class {!r} define {!r} but do not utilize {!r} as a metaclass".format(71 name, "__kwargs__", InitSubclassMeta.__name__72 )73 raise TypeError(error)74 elif dct_had_kwargs:75 type.__delattr__(cls, "__kwargs__")76 return cls77class InitSubclass(six.with_metaclass(InitSubclassMeta, object)):78 """Class that backports the functionality of `__init_subclass__` from PEP 487 to Python 2.7"""79 __slots__ = ()80 if sys.version_info[:3] < (3, 6):81 def __init_subclass__(cls):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful