GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Set difference unexpectedly permissive · Issue #1840 · python/typeshed

Set difference unexpectedly permissive #1840

New issue
Copy link
New issue
Copy link
Closed
#3886
Closed
Set difference unexpectedly permissive#1840
#3886
Copy link
Labels
stubs: false negativeType checkers do not report an error, but should

Description

@chadaustin
chadaustin
opened on Jan 22, 2018
Issue body actions

Mypy passes accepts the following snippet, even though the set subtraction is guaranteed to be a no-op.

    a: Set[str] = set(["hello"])
    b: Set[bytes] = set([b"world"])
    b -= a

Would it make sense to require Set[T] for both arguments to a difference operation?

Activity

  1. gvanrossum commented on Jan 24, 2018

    @gvanrossum
    gvanrossum
    on Jan 24, 2018
    Member
    More actions

    But if we did that, wouldn't mypy just infer T as object and still allow it?

  2. chadaustin commented on Jan 24, 2018

    @chadaustin
    chadaustin
    on Jan 24, 2018
    Author
    More actions

    In context, I had the function's return type as List[bytes], and the return statement return sorted(b - a), so even if sorted(b - a) returned List[object], I'd still see a type error when it checks against List[bytes], right?

  3. gvanrossum commented on Jan 24, 2018

    @gvanrossum
    gvanrossum
    on Jan 24, 2018 via email
    Member
    More actions
    Yeah, but the point is that the set operation itself wouldn't get the error -- and in some cases the error would come much later and surprise people.
  4. chadaustin commented on Jan 24, 2018

    @chadaustin
    chadaustin
    on Jan 24, 2018
    Author
    More actions

    Better a surprising type error (easily diagnosed with reveal_type) than shipping a no-op to production, as I did before submitting this issue. :)

  5. srittau
    added
    stubs: false positiveType checkers report false errors
    size-small
    on Oct 28, 2018
  6. srittau commented on Oct 28, 2018

    @srittau
    srittau
    on Oct 28, 2018
    Collaborator
    More actions

    Changing object to _T in this line:

    typeshed/stdlib/3/builtins.pyi

    Line 717 in 9ee4582

    def __isub__(self, s: AbstractSet[object]) -> Set[_T]: ...

    makes mypy complain about the last line in the example above. This seems reasonable to me. (Similar to the other set operations.) This is also in line with the other container types. For example, we only ordering comparisons between lists of the same type, but for sets we allow any set. This is inconsistent.

  7. srittau
    added
    stubs: false negativeType checkers do not report an error, but should
    and removed
    stubs: false positiveType checkers report false errors
    on Oct 31, 2018
  8. proost
    added 2 commits that reference this issue on Mar 28, 2020

    set difference strictly: fix python#1840

    This issue will close once commit 2f03dc7 is merged into the 'master' branch.
    2f03dc7

    set difference strictly: fix python#1840

    This issue will close once commit 22ffd19 is merged into the 'master' branch.
    22ffd19
  9. srittau
    closed this as completedin #3886on Sep 17, 2020
  10. srittau
    added a commit that references this issue on Sep 17, 2020

    set difference strictly (#3886)

    This issue will close once commit b186563 is merged into the 'main' branch.
    b186563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.