# A function that uses requests in order get JSON content

Any typing, or other improvements that you could make for this simple function?

def get_json_parsed_from(url: Union[str, bytes]) -> Dict[Any, Any]:
"""Gets a JSON file and returns it parsed, or returns an empty dict if any error occurred."""
try:
except BaseException:
_LOGGER.exception('Failed getting JSON from %s', repr(url), exc_info=False)
return {}

• Please do not update the code in your question to incorporate feedback from answers, doing so goes against the Question + Answer style of Code Review. This is not a forum where you should keep the most updated version in your question. Please see what you may and may not do after receiving answers. – Vogel612 Mar 10 '19 at 22:06

headers = random_headers()

• You are not using headers. You create it and adding the Accept key to it, but then passing a new call to random_headers() to .get instead of using headers.

• requests.get(...).json() already returns a dict. Passing it to dict(...) is superfluous.

headers = random_headers()

• You know what's strange? When I don't surround it with dict(), mypy complains that warning: Returning Any from function declared to return "Dict[Any, Any]". Is this mypy being wrong? Also, if I look up the method definition of .json() in PyCharm, I see def json(self, **kwargs: Any) -> Any. It says it returns Any. – Laurențiu Andronache Mar 10 '19 at 11:44
• Wow, good spotting on the headers issue! You're a freaking genius! Thank you! – Laurențiu Andronache Mar 10 '19 at 11:46
• @jonrsharpe so then, in the function signature I should have -> Any:, right? – Laurențiu Andronache Mar 16 '19 at 7:45