Skip to content

Fix return type for SymbolTable.get_identifiers - #8054

Merged
srittau merged 2 commits into
python:masterfrom
pamelafox:patch-1
Jun 10, 2022
Merged

srittau merged 2 commits into
python:masterfrom
pamelafox:patch-1

Conversation

@pamelafox

Copy link
Copy Markdown
Contributor

Per my PR to cpython (python/cpython#93661), the documentation for SymbolTable.get_identifiers incorrectly says it returns a list, and thats what typeshed currently says as well.

This PR changes it to return dict_keys[str, int]

Here's code that shows get_identifiers in action:

>>> import symtable
>>> code = """
... def calc_pow(a, b):
...     return a ** b
... a = 1
... b = 2
... c = calc_pow(a,b)
... """
>>> 
>>> _st = symtable.symtable(code, "example.py", "exec")
>>> _st.get_identifiers()
dict_keys(['calc_pow', 'a', 'b', 'c'])
>>> _st.get_identifiers().mapping
mappingproxy({'calc_pow': 2066, 'a': 2066, 'b': 2066, 'c': 2050})
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau
srittau merged commit b4c3e2c into python:master Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants