Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-37032: Add CodeType.replace() method#13542

Merged
vstinner merged 5 commits into
python:masterpython/cpython:masterfrom
vstinner:code_replaceCopy head branch name to clipboard
May 24, 2019
Merged

bpo-37032: Add CodeType.replace() method#13542
vstinner merged 5 commits into
python:masterpython/cpython:masterfrom
vstinner:code_replaceCopy head branch name to clipboard

Conversation

@vstinner

@vstinner vstinner commented May 24, 2019

Copy link
Copy Markdown
Member

@vstinner

Copy link
Copy Markdown
Member Author

The docstring shows default values whereas... there are no default values. I'm not sure how to fix the Argument Clinic part. @serhiy-storchaka: any idea?

replace(self, /, *, co_argcount=-1, co_posonlyargcount=-1, co_kwonlyargcount=-1,
  co_nlocals=-1, co_stacksize=-1, co_flags=-1, co_firstlineno=-1, co_code=None,
  co_consts=None, co_names=None, co_varnames=None, co_freevars=None,
  co_cellvars=None, co_filename=None, co_name=None, co_lnotab=None)
    Return a new code object with new specified fields.

@pablogsal

Copy link
Copy Markdown
Member

The docstring shows default values whereas... there are no default values. I'm not sure how to fix the Argument Clinic part. @serhiy-storchaka: any idea?

I don't know if is possible to eliminate the defaults but if you want all to display None you can use something like:

Py_ssize_t(accept={int, NoneType}, c_default="self->the_argument") = None

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I left a comment on a possible way to have al defaults to None

@vstinner

Copy link
Copy Markdown
Member Author

Py_ssize_t(accept={int, NoneType}, c_default="self->the_argument") = None

I expect that "code.replace(co_argcount=None)" raises a TypeError, since None is an invalid value. Moreover, Py_ssize_t requires to manually downcast to int... I prefer to keep "=-1" for int parameters and "=None" for other types.

I will go with the current implementation ;-)

@vstinner vstinner merged commit a9f05d6 into python:master May 24, 2019
@vstinner vstinner deleted the code_replace branch May 24, 2019 21:57
@serhiy-storchaka

Copy link
Copy Markdown
Member

I'm not sure how to fix the Argument Clinic part.

Currently it is not possible.

@pitrou

pitrou commented May 29, 2019

Copy link
Copy Markdown
Member

@pierreglaser @ogrisel You may like this change.

@asottile

asottile commented Nov 9, 2019

Copy link
Copy Markdown
Contributor

Is there a place where this can be documented? I had to find this PR to see how to use this function

@vstinner

Copy link
Copy Markdown
Member Author

Is there a place where this can be documented? I had to find this PR to see how to use this function

CodeType is only documented at:
https://docs.python.org/dev/library/types.html#types.CodeType

The replace() method can be documented there.

@asottile

asottile commented Jan 1, 2020

Copy link
Copy Markdown
Contributor

I'm a little slow on the draw here, but I wrote up a PR to document this: #17776

DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
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.

8 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.