Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented May 24, 2019

@vstinner
Copy link
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
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

Copy link
Member

@pablogsal pablogsal left a comment

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
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
Member

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

Currently it is not possible.

@pitrou
Copy link
Member

pitrou commented May 29, 2019

@pierreglaser @ogrisel You may like this change.

@asottile
Copy link
Contributor

asottile commented Nov 9, 2019

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
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
Copy link
Contributor

asottile commented Jan 1, 2020

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