-2

whilst digging into encoding/decoding, I found the following part in binascii.py:

def a2b_base64(*args, **kwargs): # real signature unknown
""" Decode a line of base64 data. """
    pass

From my naive understanding, this is implemented as C somewhere else. Is this in the python.exe itself or am I missing something?

Bishonen_PL
  • 1,400
  • 4
  • 18
  • 31
  • Your posted code snippet does nothing – EdChum Oct 23 '18 at 14:25
  • 2
    The Python library **has no `binascii.py` file**. Are you looking at something else, like stub files for autocompletion in an IDE perhaps? – Martijn Pieters Oct 23 '18 at 14:26
  • Yes, I seem to have been looking at the stub file whilst 'over-using' CTRL+B in pycharm. How does python know where the following line is then? return binascii.a2b_base64(s) – Bishonen_PL Oct 23 '18 at 14:29

1 Answers1

1

There is no binascii.py file in the Python standard library. The binascii module in Python is entirely written in C; it's implemented in the Modules/binascii.c source file.

When Python is installed on a system, available as a shared library object, so as a .so or .dll file in a lib/pythonx.x/lib-dynload directory somewhere.

What you found instead is a stub file, to aid an IDE in introspection and autocompletion tasks. Such a file is needed because extension modules written in C usually are not introspectable, you can't always use the normal introspection techniques to figure out what arguments a function written in a compiled language will accept.

Note that such files are slowly becoming obsolete as more and more code in the standard library is being converted to using the new argument clinic system, which enables introspection support. The binascii module has been updated to use the AC syntax starting in Python 3.4, so you could ask the module directly:

>>> import inspect, binascii
>>> inspect.signature(binascii.a2b_base64)
<Signature (data, /)>

The function accepts a single positional-only argument named data (see Python: What does the slash mean in the output of help(range)? for an explanation for what the / in the signature means or what positional only means).

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343