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

Add inspect.Signature.from_callable() #61575

Closed
ericsnowcurrently opened this issue Mar 7, 2013 · 10 comments
Closed

Add inspect.Signature.from_callable() #61575

ericsnowcurrently opened this issue Mar 7, 2013 · 10 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Mar 7, 2013

BPO 17373
Nosy @larryhastings, @asvetlov, @ericsnowcurrently, @1st1
Files
  • signature-from-callable.diff
  • 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 = 'https://github.com/1st1'
    closed_at = <Date 2014-03-27.16:12:02.012>
    created_at = <Date 2013-03-07.07:51:49.637>
    labels = ['type-feature', 'library']
    title = 'Add inspect.Signature.from_callable()'
    updated_at = <Date 2014-03-27.16:26:33.718>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2014-03-27.16:26:33.718>
    actor = 'eric.snow'
    assignee = 'yselivanov'
    closed = True
    closed_date = <Date 2014-03-27.16:12:02.012>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2013-03-07.07:51:49.637>
    creator = 'eric.snow'
    dependencies = []
    files = ['29333']
    hgrepos = []
    issue_num = 17373
    keywords = ['patch']
    message_count = 10.0
    messages = ['183636', '183900', '207918', '207970', '207971', '207972', '207973', '207974', '214961', '214965']
    nosy_count = 5.0
    nosy_names = ['larry', 'asvetlov', 'python-dev', 'eric.snow', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue17373'
    versions = ['Python 3.5']

    @ericsnowcurrently
    Copy link
    Member Author

    ericsnowcurrently commented Mar 7, 2013

    While working on a subclass of inspect.Signature, I realized that inspect.signature is treated as the constructor. So subclassing isn't so simple. At first I considered adding an extra parameter to inspect.signature allowing different Signature classes. Not much later it became clear that all that code should simply be in classmethod. I've called it Signature.from_callable. Patch attached.

    @ericsnowcurrently ericsnowcurrently added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 7, 2013
    @asvetlov
    Copy link
    Contributor

    asvetlov commented Mar 10, 2013

    Agree in general, but you need to update the docs also.

    @1st1
    Copy link
    Member

    1st1 commented Jan 11, 2014

    Hi Eric,

    I'm not sure why do you want this. Having "Signature.from_callable" does not allow you to change behaviour of 'inspect.signature' function. More over, it creates a confusion about what API should be used - 'inspect.signature' or 'inspect.Signature.from_callable'.

    @ericsnowcurrently
    Copy link
    Member Author

    ericsnowcurrently commented Jan 12, 2014

    The difference is that inspect.signature is not friendly to Signature
    subclasses. Without from_callable you can't customize the behavior in
    inspect.signature easily.

    @1st1
    Copy link
    Member

    1st1 commented Jan 12, 2014

    The difference is that inspect.signature is not friendly to Signature
    subclasses. Without from_callable you can't customize the behavior in
    inspect.signature easily.

    OK, suppose you have "Signature.from_callable". You then create a subclass
    MySignature, and override it. How can you customize 'inspect.signature' to
    use the MySignature class?

    @1st1
    Copy link
    Member

    1st1 commented Jan 12, 2014

    Eric,

    Moreover, 'Signature.from_function' and newly added 'Signature.from_builtin'
    are private API, or implementation detail (they are not part of PEP, not
    mentioned in the docs). If at some point it is needed to rewrite Signature
    in C, probably those two won't be a part of a new implementation.

    @ericsnowcurrently
    Copy link
    Member Author

    ericsnowcurrently commented Jan 12, 2014

    It's not about customizing inspect.signature. It's about customizing the
    nice behavior of that function, including what type it returns.

    @1st1
    Copy link
    Member

    1st1 commented Jan 12, 2014

    OK, got it now.

    Green light from me. Looking through the code, I saw that 'from_builtin' doesn't use the 'Signature._parameter_cls' (as in from_function). That's probably needs to be fixed as well, maybe in a separate issue.

    @1st1 1st1 self-assigned this Feb 25, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 27, 2014

    New changeset 8a4e44473fdd by Yury Selivanov in branch 'default':
    inspect.Signature: Add 'Signature.from_callable' classmethod. Closes bpo-17373
    http://hg.python.org/cpython/rev/8a4e44473fdd

    @python-dev python-dev mannequin closed this as completed Mar 27, 2014
    @ericsnowcurrently
    Copy link
    Member Author

    ericsnowcurrently commented Mar 27, 2014

    Thanks, Yury!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants