Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

> BTW how else are methods/functions are created in Python except via def?

Functions are objects like everything else in Python, so they have a 
type, which has a constructor:

    from types import FunctionType

The documentation for FunctionType is a bit thin, so you may need to 
experiment a bit to get the details right, but it can be done.

Unfortunately copy.copy doesn't actually copy functions, which is in my 
opinion a bug (see #39805) but if you search the internet, you will find 
code that makes independent copies of function objects.

Methods are different from functions, and like functions, they 
too have a type with a constructor:

    from types import MethodType

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39800>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to