Skip to content

Conversation

Yaminyam
Copy link
Contributor

No description provided.

@Yaminyam Yaminyam marked this pull request as draft August 16, 2022 05:33
Yaminyam and others added 4 commits August 16, 2022 16:09
Co-authored-by: Jeong YunWon <69878+youknowone@users.noreply.github.com>
@youknowone youknowone added the z-ca-2022 Tag to track contrubution-academy 2022 label Aug 16, 2022

#[pyfunction]
fn localeconv(vm: &VirtualMachine) -> PyResult<PyStrRef> {
let result = unsafe { libc::localeconv() };
Copy link
Contributor

Choose a reason for hiding this comment

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

In the current Windows version of the libc crate, this function and its return type are both missing.

@fanninpm
Copy link
Contributor

I don't think this particular module belongs in the stdlib crate:

>>> import _locale
>>> _locale.__file__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module '_locale' has no attribute '__file__'. Did you mean: '__name__'?

I think it should belong in the vm crate instead. What do you think, @youknowone?

@youknowone
Copy link
Member

@fanninpm Interesting. Does __file__ attribute existence different by it is builtin or not?

I usually check sys.builtin_module_names

>>> import sys
>>> sys.builtin_module_names
('_abc', '_ast', '_codecs', '_collections', '_functools', '_imp', '_io', '_locale', '_operator', '_signal', '_sre', '_stat', '_string', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', 'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'posix', 'pwd', 'sys', 'time', 'xxsubtype')
>>> '_locale' in sys.builtin_module_names
True

Yes, so this belongs in vm crate.

@fanninpm
Copy link
Contributor

Does __file__ attribute existence different by it is builtin or not?

Let's see:

>>> import argparse # pure-python module
>>> argparse.__file__
'/usr/lib/python3.10/argparse.py'
>>> import mmap # dynamically-linked c module
>>> mmap.__file__
'/usr/lib/python3.10/lib-dynload/mmap.cpython-310-x86_64-linux-gnu.so'
>>> import gc # statically-linked c module
>>> gc.__file__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'gc' has no attribute '__file__'. Did you mean: '__name__'?

The Python docs say that the __file__ attribute is

The pathname of the file from which the module was loaded, if it was loaded from a file. The __file__ attribute may be missing for certain types of modules, such as C modules that are statically linked into the interpreter. For extension modules loaded dynamically from a shared library, it’s the pathname of the shared library file.

@youknowone
Copy link
Member

Thanks! I didn't know that.

@youknowone
Copy link
Member

Thank you for contributing. This is not implemented by #4558

@youknowone youknowone closed this Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
z-ca-2022 Tag to track contrubution-academy 2022
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants