special support for types from importlib.import_module and pkgutil.resolve_name with Literal arguments
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
Please provide more information to help us understand the issue:
- Are you reporting a bug, or opening a feature request? Feature
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
def get_mock_module(v: Literal["mock"] | Literal["unittest.mock"]) -> ...:
return pkgutils.resolve_name(v)
- What is the actual behavior/output? Any
- What is the behavior/output you expect? Module["mock"] | Module["unittest.mock"]
- What are the versions of mypy and Python you are using? git master
Do you see the same issue after installing mypy from Git master? yes - What are the mypy flags you are using? (For example --strict-optional)
--strict
I think https://github.com/python/mypy/issues/5059 was closed because it was opened as a bug rather than a feature request
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with mypy --strict, focusing on importlib.import_module and pkgutil.resolve_name when passed Literal arguments. Trace how mypy currently analyzes these calls; done means the example is inferred as Module["mock"] | Module["unittest.mock"] without errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100