Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6209905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:04:05+00:00 2026-05-24T06:04:05+00:00

Why does PEP-343 use type() in this situation here? mgr = (EXPR) exit =

  • 0

Why does PEP-343 use type() in this situation here?

    mgr = (EXPR)
    exit = type(mgr).__exit__  # Not calling it yet
    value = type(mgr).__enter__(mgr)

Couldn’t we just as well use exit = mgr.__exit__ and value = mgr.__enter__()? Seems simpler to me, but I assume I’m missing something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:04:05+00:00Added an answer on May 24, 2026 at 6:04 am

    Of course the PEP could use attributes of the instance itself instead of attributes of the type, but this would be in contrast to the use of special methods in Python. For example

    a + b
    

    is translated to

    type(a).__add__(a, b)
    

    and not to

    a.__add__(b)
    

    as shown by the following example:

    >>> class MyInt(int):
    ...     pass
    ... 
    >>> a = MyInt(3)
    >>> b = MyInt(4)
    >>> a + b
    7
    >>> a.__add__ = lambda self, other: 42
    >>> a + b
    7
    

    So, to be consistent with the rest of Python, the special methods __enter__() and __exit__() should also be looked up in the type’s dictionary first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone use have a good regex library that they like to use? Most
Does anyone know where Control.ShouldSerializeVisible is called from? The Reflector does not show it
Depending on your interpretation this may or may not be a rhetorical question, but
Does the model binder not suport arrays of JSON objects? The code below works
Does anyone know how to use the define function and pass a variable into
I am trying to use an 'ordered class' as described in PEP 3115 (that
Does anyone know a trick that would allow me to do something like this
Does anyone see any issues with this basic test? var GC_MemoryStart = System.GC.GetTotalMemory(true); Stopwatch
Does Google force employees who have offers from Facebook to leave immediately?
Does anyone remember the XMP tag? What was it used for and why was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.