Skip to content

builtins stubtest exceptions - #5219

Merged
JelleZijlstra merged 3 commits into
python:masterfrom
hatal175:builtins
Apr 16, 2021
Merged

JelleZijlstra merged 3 commits into
python:masterfrom
hatal175:builtins

Conversation

@hatal175

Copy link
Copy Markdown
Contributor
  • I've just left 'class function' - anyone can explain what it is and why it is there?

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pip (https://github.com/pypa/pip.git)
+ src/pip/_internal/operations/install/wheel.py:620: error: Incompatible types in assignment (expression has type "chain[File]", variable has type "map[File]")
+ src/pip/_internal/operations/install/wheel.py:646: error: Incompatible types in assignment (expression has type "filterfalse[File]", variable has type "map[File]")
+ src/pip/_internal/operations/install/wheel.py:650: error: Incompatible types in assignment (expression has type "chain[File]", variable has type "map[File]")


bidict (https://github.com/jab/bidict.git)
+ bidict/_orderedbidict.py:63: error: "object" not callable

@hauntsaninja

Copy link
Copy Markdown
Collaborator

There's #2999 for builtins.function

Comment thread tests/stubtest_whitelists/py3_common.txt Outdated
Comment thread tests/stubtest_whitelists/py3_common.txt Outdated
@JelleZijlstra

Copy link
Copy Markdown
Member

The bidictfailure is a bit nasty: it's on a line key = next((reversed if last else iter)(self)). This doesn't work any more because now mypy infers object for reversed if last else iter. Still, this sort of issue seems rare so I'm OK with moving forward with these changes.

hatal175 and others added 2 commits April 15, 2021 07:42
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pip (https://github.com/pypa/pip.git)
+ src/pip/_internal/operations/install/wheel.py:620: error: Incompatible types in assignment (expression has type "chain[File]", variable has type "map[File]")
+ src/pip/_internal/operations/install/wheel.py:646: error: Incompatible types in assignment (expression has type "filterfalse[File]", variable has type "map[File]")
+ src/pip/_internal/operations/install/wheel.py:650: error: Incompatible types in assignment (expression has type "chain[File]", variable has type "map[File]")


bidict (https://github.com/jab/bidict.git)
+ bidict/_orderedbidict.py:63: error: "object" not callable

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pip (https://github.com/pypa/pip.git)
+ src/pip/_internal/operations/install/wheel.py:620: error: Incompatible types in assignment (expression has type "chain[File]", variable has type "map[File]")
+ src/pip/_internal/operations/install/wheel.py:646: error: Incompatible types in assignment (expression has type "filterfalse[File]", variable has type "map[File]")
+ src/pip/_internal/operations/install/wheel.py:650: error: Incompatible types in assignment (expression has type "chain[File]", variable has type "map[File]")


bidict (https://github.com/jab/bidict.git)
+ bidict/_orderedbidict.py:63: error: "object" not callable

Comment thread stdlib/builtins.pyi
def __iter__(self) -> Iterator[int]: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __int__(self) -> int: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if these were added on purpose to make bytes fulfill the SupportsInt and SupportsFloat protocols. int(b'12') works at runtime. Probably safer to keep them.

@hatal175 hatal175 Apr 16, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. no mypy primer diffs
  2. the int __new__ function specifically gets bytes (so does float) and treats it as a string: https://github.com/python/cpython/blob/62ec63864822de1dd1933225584e8503ac40c1f9/Objects/longobject.c#L4960
  3. Other functions that receive SupportsInt fail on bytes - itertools.count(b'1',1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good, I will merge

@JelleZijlstra
JelleZijlstra merged commit d3b2caf into python:master Apr 16, 2021
@hatal175
hatal175 deleted the builtins branch April 16, 2021 17:43
@ktbarrett

Copy link
Copy Markdown
Contributor

Why were all these overloaded functions changed to classes? This breaks deduction in certain contexts.

@Akuli

Akuli commented Jul 30, 2021

Copy link
Copy Markdown
Collaborator

I'm not yet convinced that this PR has anything to do with that. I added this function to your mypy playground link, based on what this PR deletes, and used it instead of zip:

def myzip(__iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]:
    return zip(__iter1, __iter2)

It still gives the same number of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants