Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins stubtest exceptions #5219

Merged
merged 3 commits into from
Apr 16, 2021
Merged

builtins stubtest exceptions #5219

merged 3 commits into from
Apr 16, 2021

Conversation

hatal175
Copy link
Contributor

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

@github-actions
Copy link
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
Collaborator

There's #2999 for builtins.function

@JelleZijlstra
Copy link
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
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
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

def __len__(self) -> int: ...
def __iter__(self) -> Iterator[int]: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __int__(self) -> int: ...
Copy link
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.

Copy link
Contributor Author

@hatal175 hatal175 Apr 16, 2021

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
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
Contributor

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

@Akuli
Copy link
Collaborator

Akuli commented Jul 30, 2021

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.

None yet

5 participants