2

I have installed Visual Studio 2013 Community and Python Tools for Visual Studio 2.1 with Python 3.4.2 on Windows Server 2012. The intellisense does not appear to be working correctly

import gspread
import requests
import json

# correctly calls gc a 'client' type
gc = gspread.login('<user_name redacted>','<password redacted>')
# correctly calls wks a 'Worksheet' type
wks = gc.open('testing_sheet').sheet1

# INCORRECTLY calls the json_test object a 'boolean, NoneType, float, int, object' type
json_test = json.loads('{"chicken":"cluck"}')

# correctly calls post_data a 'dict' type
post_data = {'item':'abc'}
# correctly calls post_headers a 'dict' type
post_headers = {'content-encoding': 'json'}
# INCORRECTLY calls post_requests a 'bool' type, should be type 'Response'
post_requests = requests.post(url = '<redacted>', data = json.dumps(post_data), headers = post_headers)

I have tried rebuilding the DB several times, uninstalled and reinstalled Python and PTVS but it always incorrectly identifies these objects. Am I doing something wrong? Is there something more I can do?

4

1 回答 1

1

PTVS 中的 IntelliSense 由类型推理引擎驱动。由于 Python 本身最终是一种动态类型语言,它只能做这么多,并且必须对正在发生的事情做出假设和猜测。例如,在 的情况下json.loads,它会查看代码,分析通过它的所有可能的代码路径,并生成每个类型的联合。因此,如果json.loads可以为某些输入返回 bool(如果输入本身是布尔文字,它可以返回),那么该类型将列在返回类型中。然后完成列表将包括联合中所有类型的成员,每个成员都标有它来自的类型的名称。

object我相信,之所以出现在列表中,是因为object_hook回调允许几乎任意 JSON 解码。)

没有做的一件事是实际上尝试运行代码以查看您传递给它的字符串将被解析为什么。所以不要指望在 IntelliSense 中看到带有“chicken”等的特定字典。

不过,for 的完成requests看起来确实是错误的。我建议提交一个错误

于 2014-11-19T19:38:57.037 回答