init
This commit is contained in:
commit
38355d2442
9083 changed files with 1225834 additions and 0 deletions
34
.venv/lib/python3.8/site-packages/mypy/split_namespace.py
Normal file
34
.venv/lib/python3.8/site-packages/mypy/split_namespace.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""Split namespace for argparse to allow separating options by prefix.
|
||||
|
||||
We use this to direct some options to an Options object and some to a
|
||||
regular namespace.
|
||||
"""
|
||||
|
||||
# In its own file largely because mypyc doesn't support its use of
|
||||
# __getattr__/__setattr__ and has some issues with __dict__
|
||||
|
||||
import argparse
|
||||
|
||||
from typing import Tuple, Any
|
||||
|
||||
|
||||
class SplitNamespace(argparse.Namespace):
|
||||
def __init__(self, standard_namespace: object, alt_namespace: object, alt_prefix: str) -> None:
|
||||
self.__dict__['_standard_namespace'] = standard_namespace
|
||||
self.__dict__['_alt_namespace'] = alt_namespace
|
||||
self.__dict__['_alt_prefix'] = alt_prefix
|
||||
|
||||
def _get(self) -> Tuple[Any, Any]:
|
||||
return (self._standard_namespace, self._alt_namespace)
|
||||
|
||||
def __setattr__(self, name: str, value: Any) -> None:
|
||||
if name.startswith(self._alt_prefix):
|
||||
setattr(self._alt_namespace, name[len(self._alt_prefix):], value)
|
||||
else:
|
||||
setattr(self._standard_namespace, name, value)
|
||||
|
||||
def __getattr__(self, name: str) -> Any:
|
||||
if name.startswith(self._alt_prefix):
|
||||
return getattr(self._alt_namespace, name[len(self._alt_prefix):])
|
||||
else:
|
||||
return getattr(self._standard_namespace, name)
|
||||
Loading…
Add table
Add a link
Reference in a new issue