python / python/mypy

TypeGuard may spuriously narrow Any -> object

Open
#10,554 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-typeguard-typeis
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

I haven't had time to fully reduce this, but in the Sphinx code at https://github.com/sphinx-doc/sphinx/blob/1d4c414319598320f95eed245e4a2f9ad3e5a668/sphinx/ext/coverage.py#L218, the TypeGuards introduced by python/typeshed#5473 lead to an incorrect error:

+ sphinx/ext/coverage.py: note: In member "build_py_coverage" of class "CoverageBuilder":
+ sphinx/ext/coverage.py:218:51: error: Item "object" of "Union[object, object]" has no attribute "__doc__"

Seems like some bad interaction with the negative case for the TypeGuards produced by ismethod and isfunction a few lines up.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with sphinx/ext/coverage.py around line 218 and reproduce the reported error involving the TypeGuards from ismethod and isfunction. Reduce the Sphinx case to a focused example of Any narrowing; done means the valid doc access no longer reports an object-member error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.