예제 #1
0
파일: __init__.py 프로젝트: steff456/jedi
    def __init__(self, source, namespaces, **kwds):
        """
        Parse `source` and mixin interpreted Python objects from `namespaces`.

        :type source: str
        :arg  source: Code to parse.
        :type namespaces: list of dict
        :arg  namespaces: a list of namespace dictionaries such as the one
                          returned by :func:`locals`.

        Other optional arguments are same as the ones for :class:`Script`.
        If `line` and `column` are None, they are assumed be at the end of
        `source`.
        """
        try:
            namespaces = [dict(n) for n in namespaces]
        except Exception:
            raise TypeError("namespaces must be a non-empty list of dicts.")

        environment = kwds.get('environment', None)
        if environment is None:
            environment = InterpreterEnvironment()
        else:
            if not isinstance(environment, InterpreterEnvironment):
                raise TypeError(
                    "The environment needs to be an InterpreterEnvironment subclass."
                )

        super(Interpreter, self).__init__(source,
                                          environment=environment,
                                          _project=Project(os.getcwd()),
                                          **kwds)
        self.namespaces = namespaces
        self._inference_state.allow_descriptor_getattr = self._allow_descriptor_getattr_default
예제 #2
0
    def __init__(self, code, namespaces, *, project=None, **kwds):
        try:
            namespaces = [dict(n) for n in namespaces]
        except Exception:
            raise TypeError("namespaces must be a non-empty list of dicts.")

        environment = kwds.get('environment', None)
        if environment is None:
            environment = InterpreterEnvironment()
        else:
            if not isinstance(environment, InterpreterEnvironment):
                raise TypeError(
                    "The environment needs to be an InterpreterEnvironment subclass."
                )

        if project is None:
            project = Project(Path.cwd())

        super().__init__(code,
                         environment=environment,
                         project=project,
                         **kwds)

        self.namespaces = namespaces
        self._inference_state.allow_descriptor_getattr = self._allow_descriptor_getattr_default
예제 #3
0
def environment(request):
    if request.config.option.interpreter_env:
        return InterpreterEnvironment()

    version = request.config.option.env
    if version is None:
        version = os.environ.get('JEDI_TEST_ENVIRONMENT', str(py_version))

    return get_system_environment(version[0] + '.' + version[1:])
예제 #4
0
파일: conftest.py 프로젝트: yongquanf/jedi
def environment(request):
    version = request.config.option.env
    if version is None:
        v = str(sys.version_info[0]) + str(sys.version_info[1])
        version = os.environ.get('JEDI_TEST_ENVIRONMENT', v)

    if request.config.option.interpreter_env or version == 'interpreter':
        return InterpreterEnvironment()

    return get_system_environment(version[0] + '.' + version[1:])
예제 #5
0
파일: __init__.py 프로젝트: syntonym/jedi
    def _get_evaluator(self, function, evaluator_id):
        from jedi.evaluate import Evaluator

        try:
            evaluator = self._evaluators[evaluator_id]
        except KeyError:
            from jedi.api.environment import InterpreterEnvironment
            evaluator = Evaluator(
                # The project is not actually needed. Nothing should need to
                # access it.
                project=None,
                environment=InterpreterEnvironment())
            self._evaluators[evaluator_id] = evaluator
        return evaluator
    def _get_inference_state(self, function, inference_state_id):
        from jedi.inference import InferenceState

        try:
            inference_state = self._inference_states[inference_state_id]
        except KeyError:
            from jedi.api.environment import InterpreterEnvironment
            inference_state = InferenceState(
                # The project is not actually needed. Nothing should need to
                # access it.
                project=None,
                environment=InterpreterEnvironment()
            )
            self._inference_states[inference_state_id] = inference_state
        return inference_state
예제 #7
0
def same_process_inference_state(Script):
    return Script('', environment=InterpreterEnvironment())._inference_state
예제 #8
0
파일: conftest.py 프로젝트: laduygaga/vimrc
def same_process_evaluator(Script):
    return Script('', environment=InterpreterEnvironment())._evaluator