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 — isinstance(x, typing.Protocol-class) unexpectedly evaluates properties · Issue #89445 · python/cpython

isinstance(x, typing.Protocol-class) unexpectedly evaluates properties #89445

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
isinstance(x, typing.Protocol-class) unexpectedly evaluates properties#89445
Copy link
Labels
3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

daitakahashi
mannequin
opened on Sep 24, 2021
Issue body actions
BPO 45282
Nosy @AlexWaygood, @daitakahashi
Files
  • test_protocol_property.py: testcases
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-09-24.13:25:14.862>
    labels = ['type-bug', '3.8', '3.9']
    title = 'isinstance(x, typing.Protocol-class) unexpectedly evaluates properties'
    updated_at = <Date 2021-09-24.14:52:18.540>
    user = 'https://github.com/daitakahashi'

    bugs.python.org fields:

    activity = <Date 2021-09-24.14:52:18.540>
    actor = 'AlexWaygood'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2021-09-24.13:25:14.862>
    creator = 'daitakahashi'
    dependencies = []
    files = ['50303']
    hgrepos = []
    issue_num = 45282
    keywords = []
    message_count = 2.0
    messages = ['402562', '402567']
    nosy_count = 2.0
    nosy_names = ['AlexWaygood', 'daitakahashi']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45282'
    versions = ['Python 3.8', 'Python 3.9']

    Activity

    1. daitakahashi commented on Sep 24, 2021

      @daitakahashi
      daitakahashimannequin
      on Sep 24, 2021
      MannequinAuthor
      More actions

      Because __instancecheck__ of _ProtocolMeta uses hasattr() and getattr(), both of which evaluate property attributes, calling isinstance() with an object and a class that inherits typing.Protocol evaluates the input object's properties in some cases.

      The attached testcases include three cases of checking subtype relationship of an instance (having a property "x" that may raise RuntimeError on evaluation) and following three protocol classes;
      (1) a protocol class having "x" as a property,
      (2) a protocol class having "x" as a data attribute, and
      (3) a protocol class having "x" as a class property that raises
      RuntimeError on evaluation (>= python 3.9 only).

      Expected behavior:

      1. The isinstance(obj, Protocol_class) does not evaluate anything but just checks existence of attribute names.
      2. All cases in the attached testcases run without any error

      Thank you very much in advance.

    2. daitakahashi
      added
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Sep 24, 2021
    3. AlexWaygood commented on Sep 24, 2021

      @AlexWaygood
      AlexWaygood
      on Sep 24, 2021
      Member
      More actions

      Related: https://bugs.python.org/issue44904

    4. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    5. AlexWaygood
      added
      topic-typing
      on Apr 13, 2022
    6. AlexWaygood commented on Mar 5, 2023

      @AlexWaygood
      AlexWaygood
      on Mar 5, 2023
      Member
      More actions

      Duplicate of #102433, which is a newer issue but has more discussion

    7. AlexWaygood
      closed this as not plannedon Mar 5, 2023
    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

      3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — 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.