Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn for the threading and thread modules #15

Closed

Conversation

nanjekyejoannah
Copy link

Dont merge until #13 and #14 are merged, some helper code cuts across.

Threading module Notes

Python 2:

>>> from thread import get_ident
>>> from threading import get_ident
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name get_ident
>>> import threading
>>> from threading import _get_ident
>>>

Python 3:

>>> from threading import get_ident
>>> from thread import get_ident
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'thread'
>

Note:

There is no neutral way of porting

@@ -904,6 +904,10 @@ initthread(void)
{
PyObject *m, *d;

if (PyErr_WarnPy3k_WithFix("In 3.x, the thread module is removed",
Copy link
Member

Choose a reason for hiding this comment

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

Is the threading module compatible with thread? In other words, if I e.g. turn import thread.X into import thread.X will that work? I wonder if we need more fine-grained warnings?

Copy link
Author

@nanjekyejoannah nanjekyejoannah Nov 25, 2022

Choose a reason for hiding this comment

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

Yes, good one, that is possible, we can warn both ways. For module, and the method where the warning is more fine grained e.g "thread.get_indent was removed in 3.x: use threading._ge_indent instead"

Also note even if you use the threading module, some methods were renamed to have an underscore e.g threading.get_indent is threading._get_indent there is no way to write code that works on both 2.x and 3.x for like 3 methods

Copy link
Member

Choose a reason for hiding this comment

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

Is the threading module in Python 2 compatible with Python 3? I'm wondering if we have to do some warnings in pygrate2 and some others in pygrate3?

Copy link
Author

Choose a reason for hiding this comment

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

Not completely, some methods are named with an underscore in 2.x and yet in 3.x they dont have the underscore.

Copy link
Author

Choose a reason for hiding this comment

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

3 methods are completely incompatible

Copy link
Author

Choose a reason for hiding this comment

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

Yes, do we need to forward port too? its as simple as aliasing the incompatible methods

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, if the user can change things in pygrate2, we shouldn't warn in pygrate3. But if they can't change in pygrate2, we should consider aliases & warnings in pygrate3.

Copy link
Author

Choose a reason for hiding this comment

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

OK SGTM

Copy link
Member

Choose a reason for hiding this comment

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

Should we do that in this PR? [I tend to think so, but I don't have a firm opinion.]

Copy link
Author

Choose a reason for hiding this comment

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

Onmy radar this morning, I want to handle as part of this PR

bors bot added a commit that referenced this pull request Nov 29, 2022
16: Warn for specific thread module methods r=ltratt a=nanjekyejoannah

Dont merge until #13  and  #14 are merged, some helper code cuts across.

This replaces #15 

Threading module Notes

Python 2:

```
>>> from thread import get_ident
>>> from threading import get_ident
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name get_ident
>>> import threading
>>> from threading import _get_ident
>>>
```

Python 3:

```
>>> from threading import get_ident
>>> from thread import get_ident
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'thread'
>
```

**Note:**

There is no neutral way of porting

Co-authored-by: Joannah Nanjekye <jnanjekye@python.org>
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.

3 participants